Exporting curretn recordset to Excel - only working first time!

The code below works the first time it is run - the displayed records are 
output to a excel spreadsheet called book1 with the worksheet named as it 
should be.
So you open a form and click the button on the ribbon referencing this code 
and all the displayed records are transferred to a spreadsheet.

However if you then try to run the code again without first closing and 
reopening the form you get a blank sheet.

Any ideas?

Also any idea how to make this work with an open table as well as a form. If 
I run the form on an opne table I get the error "2475 You entered an 
expression that requires a form to be the active window". Followed by an 
automation error "the object invoked had disconnected from its clients". And 
error 91 object with etc... I realise this is because I have used ActiveForm.

'revised for late binding
'define variables
Dim xlApp As Object
Dim xlWorkbook As Object

'create the excel application object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

'create a new workbook
Set xlWorkbook = xlApp.Workbooks.Add

'define variables
Dim objRST As Recordset
Dim strSheetname As String

'create the recordset
Set objRST = Screen.ActiveForm.Recordsetclone

'create a sheet name - must be 30 characters or less
strSheetname = "ANE Business System Export"

'copy data from the recordset to the cells
Dim xlsheet As Object

Set xlsheet = xlWorkbook.Sheets(1)
With xlsheet
..Cells.CopyFromRecordset objRST
..Name = strSheetname
End With

'clean up all variables
Set objRST = Nothing
Set xlsheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing
6/7/2010 12:38:27 PM
access.formscoding 7493 articles. 0 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 7


Similar Artilces:

Can you make excel auto save your workbook?
I need Excel to automaticly save my work every 2 or 3 minutes if that is possible. Can it do that? Hi what Excel version are you using? -- Regards Frank Kabel Frankfurt, Germany "Rhiannon" <Rhiannon@discussions.microsoft.com> schrieb im Newsbeitrag news:FE6930C8-D9D4-46D0-825E-0C25A02C1B71@microsoft.com... > I need Excel to automaticly save my work every 2 or 3 minutes if that is > possible. Can it do that? Excel 2003 "Frank Kabel" wrote: > Hi > what Excel version are you using? > > -- > Regards > Frank Kabel > Frankfurt, Germany &g...

Excel Pivot Table Creator Issue
Hi all, I'm unable to Export to Excel my pivot table created in the Excel Pvot Table Creator. I select my dimensions, measures, rows, and data then hit the Excel button. I keep getting the following error: Unhandled object exception: Initialization of the data source failed.Check the database server or contact your database administrator. Make sure the external database is available, and then try the operation again. If you see this message again, create a new data source to connect to the database. Any ideas? Are SQL Analysis Services running? Were all the server setup steps com...

how can I show leading zeros in excel
I am trying to input some numeric data into a spreadsheet, some of the entries have leading zeros, every time I move to the next cell, Excel changes the data by removing the leading zeros. I have tried reformating the cells in question in Number & General, both give me the same problem. Can somebody please help. Using Excel 2002. Thanks. You could either format the cell as Text (then type your data) or you can start with an apostrophe '000123 or you can use a custom format: Format|cells|number tab custom in the type box, put as many 0's as you want 000000 The first two op...

add source data to chart in excel
I can't get Excel to accept more than 19 data points for my X-axis in a chart? Is this a limit? How do I add more data points? (As soon as I try to add the 20th point, all of the other points are lost.) Hi Susan I have had this trouble in the past. Try.... Right click chart and select 'Source Data'. Delete any existing source data and close dialog box. Select the source data you require and copy it. Click on the chart and paste. Sandy "Susan" <Susan@discussions.microsoft.com> wrote in message news:C7D47720-BCF1-4066-911D-555E386F4FEB@microsoft.com... > I ...

Partially protected sheet in Excel 2007 (Win) turns into fully protected sheet
Version: 2004 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Hi! <br><br>I have to modify an Excel spreadsheet which is provided to me. On Windows, part of the sheet is password prrotected so it never is modified. If I change it under Windows, I can change the cells I am entitled to. Works fine. On Mac Excel 2004, when I open the same spereadsheet, the whole sheet is protected and Excel asks that I remove the password before I can modify the sheet. This is not very good as you can imagine. <br><br>Is there a way to fix this? Is this a bug or the e...

Replace a comma with a period in a cell containing a lastname, first name, middle i
Hello - I am trying to clean some data and need to change all of my names from McLaughlin, Victor, (i.e, comma) W to McLaughlin, Victor.(i.e., period) W Is there an extract and replace formula or method of som sort (in excel or access) that will allow me to pull the first comma from the right and replace it with a period. Thanks for any suggestions! Select the cells you want to change and run this tiny macro: Sub comma_tose() For Each r In Selection v = StrReverse(r.Value) r.Value = StrReverse(Replace(v, ",", ".", 1, 1)) Next End Sub For example: a,b,c,d wi...

Time Stamp on Inbound Mail
Is there a way to time stamp emails when they ARRIVE, vice when they are sent. Because of our SLA, we have certain timeframes to get work done in and the clock on that starts when they arrive at our facility. But, since it's time stamped with the time the user/client sent it, we are behind - as sometimes their emails don't arrive within the reasonable amount of time from when they sent it Any assistance would be greatly appreciated. A configuration, a 3rd party software, etc....... We are running Exch 2k3 & OL 2k3 Thanks Mack Outlook messages do contain a time stamp for the ti...

MS Excel file extension changed through e-mail
MS Excel .xlsx files sent as attachments are received without the x, as a .xls instead. The same is true for MS Word .docx changed to .doc Answered in the Word group. Please don't post the same question in multiple groups. It not only causes responders to waste their time replying to questions that have already been answered but it also makes it more difficult for you to follow up on the replies. If it truly is an issue that involves more than one app either post to the Office group rather than the individual groups or use a newsreader rather than the web interface & learn to ...

Problems with re-setting the last active cell in an Excel workshee
I am trying to re-set the last active cell on an Excel 2002 worksheet (in this particular sheet it should be cell DA197). I have used both the methods described in the Knowledge Base article (deleting rows and columns and re-saving; and the Excess Format Cleaner add-in). Deleting the rows and columns does not work; using the Excess Format Cleaner does not work either and it then also hides the rows from 198 to 65536 - but does not do the same for the columns. I have checked that there is no protection on the worksheet. Has anyone else come across this problem and if so can you please ...

HTML Emails sent to me in Calibri appear as Times New Roman
I've spent more of my life (ie all day) trying to find a solution to this. I work in a small business and we've just defined our default email font and have created a signature in the same font. Very weirdly when my colleague sends an email to me, having written it in Calibri on his Mac, it arrives in my inbox as TNR. Even more weirdly, when he replies to an email I have sent him (visible as Calibri in my outbox) the previous email (the chain of the conversation) turns to TNR also. This is driving me nuts and it makes us look unprofessional. Can anyone help? ...

Opening a form while another is working
I have a Master form that automatically opens when the database is opened. In the LOAD event, it does a few things that take quite a bit of time. I have another form (Wait form) that has a scrolling message telling the user to Please Wait. It uses the Timer property. My intention was to call the Wait form from the begining of the Master LOAD, then, when all the time consuming functions were done, check to make sure the Wait form is still around and close it. The problem is that the Wait form comes up but is only showing the border of the form, not the scrolling text. That area is transpare...

does VS C++ 2005 actually work????
I recently purchased Microsoft VS 2005 and just cannot seem to get it working. 1. I tried converting a VS 2002 solution to VS 2005. It took a while to realize there is a bug in Intellisense. The only solution was to disable Intellisense. 2. It seems class view has been rendered inoperable now that Intellisense has been disabled. So this means browsing by namespaces and classes is not possible. 3. I tried debugging the application but it seems the debugger cannot find certain debug libraries such as 'MFC80UD.DLL'. I posted a message and hope someone will know what is ha...

Change the working directory for a MFC application
I am trying to change the working directory of a MFC application after the application execution begins. Chdir or setcurrentdirectory doesnot work for a MFC application. Can anyone suggest how i can do this? Thanks, - Akila. Akila wrote: > I am trying to change the working directory of a MFC application after > the application execution begins. > > Chdir or setcurrentdirectory doesnot work for a MFC application. > > Can anyone suggest how i can do this? > > Thanks, > - Akila. > SetCurrentDirectory does work for a MFC application. If it doesn't seem ...

Excel Form "Component Not Registered"
I am using several excel spreadsheet that are working on many other machines but they all of a sudden started giving me a "component not registered" error. I don't know of any changes to my workstation environment. In order to debug, I stripped down the excel spreadsheet to the bare minimum. I noticed that when all the forms were removed from the spreadsheet that the problem disapeared. I removed everything in the spreadsheet except for one form and a Workbook_Open() procedure. No problem occurs if I have an empty procedure but as soon as I even put a comment in th...

Email a single Excel worksheet instead of the whole workbook.
I have an Excel workbook with several worksheets. I want to email just one of these worksheets to a friend. It would be great to be able to right-click the worksheet tab and find the option to send worksheet as an attachment. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the ...

excel database lookup
newbee done some homework on excel i wold like to have data from a database such as access be used to fill a drop down combobox if possible as user enters data in combobox i want combobox to scroll example if user enters character R i wan combobox to scroll down to r and soon as data is entered from kewboard any suggestions, url etc really appreciated Hi see your other post -- Regards Frank Kabel Frankfurt, Germany "ilaboo" <plener@earthlink.net> schrieb im Newsbeitrag news:yT_Xc.1707$JT3.423@newsread3.news.atl.earthlink.net... > newbee > done some homework on exc...

How to join date/time field when "days" are same but "time" differ
Good evening everyone, I have one TRANSACTION table that contains: 1."date/time" field (YYMMDD hh:mm:ss) 2."quantity field" And another PRICE table that contans: 1."date/time" field (YYMMDD hh:mm:ss) 2."price field" Now, I want to join the "date/time" fields so I can perform a simple "quantity * price" calculation on each transaction-row. But the time differes (hh:mm:ss) and I just can't find a way to make Access accept a relation between the days (it outputs nothing). How can I make it ignore difference in the "ti...

excel charts and graphs
I want to assemble several pages of excel charts and graph in the form of a poster without printing them out. THOR ...

insert a JPEG into EXCEL 2002
Hello - I was asked to "pretty up" an Excel invoice for work and need to place a JPEG into the file. I know I can't insert a picture into the header/footer with Excel 2002, but can't I just insert it into the body of the file? In Excel Help it simply says to click on Insert Picture, but for some reason the Insert Picture option is ALWAYS greyed out. Any suggestions? I would REALLY appreciate it! Cheers! Hi mckee You can insert a picture into the header / footer with XL 2002. Go to File>PageSetup. Select the "Headers / Footers" tab and select "Custom ...

Set the line weight with VBA in Excel 07
I applied a chart style to a chart. I had the macro recorder on while I manipulated the chart. I saw the code to change the default size of the marker, but I could not get any code to appear for adjusting the line weight of the data series while a chart style is applied. I looked in the series object model and don't see a property by which to set the line weight. The old Border property in 03 is gone. How should I adjust this programatically? Thanks. TL Hi, Try, activechart.SeriesCollection(1).format.line.weight=3 Cheers Andy TroyLee wrote: > I applied a chart style to a c...

approach to excel
Can I transfer a complete database from lotus approach to excel? Will the dats be safe afterwards Thanks Julian I would expect the data to be as safe in excel as it was in Lotus. Verify that your conversion to excel worked ok. (Depending on your version of Lotus, you may have to save it as an excel file (while in Lotus) or an earlier version of Lotus, so that excel can open it. (Excel doesn't open .123 files.) And keep backups. (I've found the biggest threat to the integrity of my data is me--not the application! I can screw up really, really fast.) Julian Campbell wrot...

Excel worksheet total up to show in another worksheet
I have two worksheets. The first is the nice printable page. On the second page I just total up my receipts. How do I get those totals to show on Worksheet 1 in a cell called Total? -- SF Hi Just say your totals to be added are in A2:A120 in Sheet 1 then =SUM(Sheet1!A2:A120) hope this help -- nik ----------------------------------------------------------------------- nika's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1536 View this thread: http://www.excelforum.com/showthread.php?threadid=31615 ...

Time formats
I am creating a template which requires the user enter a time (not present time, flight times), for example the user will be listing a number of flight arrivals and departures and what I want to do is have the user simply enter something like 804p and have the cell display it as 8:04 pm. I have looked at some custom formats and nothing seems to be able to do this. Any help would be appreciated. Thanks! Tracey ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ See http:...

Excel worksheet programming for time restrictions.
I have several cells (properties) that will be visible or not depending on the time of day. I am using VBA to set the value of the properties and need a way to use not just the TIME function to establish the system time but, a way to test for a period of time, for example the DAY SHIFT, SWING SHIFT AND GRAVEYARD SHIFT. Using If Then Else conditional statements to test the system time to a span of time to indicate the shifts aforesaid. What I am not clear on is the syntax in VBA to use when identifying the shifts and testing for conditions met. HElP? Is this any help? Dim tim0800 Dim ...

How do I put Excel data into a US map format?
I want to feed Excel data about population and trends into a map format instead of a bar graph or pie chart. Is there a plug-in or some such thing that I can use that works with Excel? Ultimately, I want to have each state depicted by a color code for a range of population or an amount of certain data. I am using Excel 2002 in a Windows XP environment. ...