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] 23


Similar Artilces:

Very annoying behaviour of Excel 2003
Each time I am opening Excel, it is installing some component. This takes several minutes, and becomes very annoying. I recently had to reinstall XP and Office from the distribution CDs. I have the problem since then. It certainly has something to do with the install. Does anyone on this forum ever experienced such a behaviour. I am running Office 2003 on XP SP3. have you tried doing a repair in the help menu? -- Gary Keramidas Excel 2003 "Jean" <Jean@discussions.microsoft.com> wrote in message news:020549D4-8070-46ED-8768-821EECD87C88@microsof...

My hide sheet option in excel is not working
My hide sheet option in Excel is not working. It is grayed out so I can not toggle nor use it to hide or unhide sheets. Security is at Medium - would appreciate any insight into how to fix this. Is the sheet protected? You cannot hide a protected sheet. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "arleen" <arleen @discussions.microsoft.com> wrote in message news:D028B90F-6DDB-4DE6-9F5C-22C137FBE927@microsoft.com... > My hide sheet option in Excel is not working. It is grayed out > so I can not > toggle n...

How do I get excel to accept (c) as text and not change to copyri.
How do I enter the text (c) in Excel without having it changed into the copyright symbol? Hi Daffyd, Try: Tools | Autocorrect | Select (c) | Delete | OK --- Regards, Norman "daffyd" <daffyd@discussions.microsoft.com> wrote in message news:8CCC3C1A-6F19-4F62-B934-8A71F236A4FD@microsoft.com... > How do I enter the text (c) in Excel without having it changed into the > copyright symbol? Go into the Tools Menu. Look for AutoCorrect. In the bottom half of the AutoCorrect Tab, look at the list for Replace text as you type. Delete the entry for (c). tj "da...

Setting series values on Excel Chart
Hi I'm struggling very hard in getting beyond this error when trying to use VB to generate a chart from data previously inserted into the sheet. Unable to set the Values property of the Series class. The code works absolutely fine in XL2007 but I am having to port it back to 2003 and the inference is that its empty values that cause it to hiccup - something I cannot avoid. My code is: 1. Retrieve selected data from database and place it at the top of the sheet 2. Add The Chart 3. Iterate through the data (amount can be variable depending upon user inputs) For j as i...

Excel template that lists each month's meetings w/ some detail
I'm looking for an Excel template that lists every month of the year with room to list weekly, monthly and quarterly meetings, including some detail for each meeting. Probably would need to be landscape oriented. The main intent is to give the person using it an idea of upcoming meetings, the intent of each and what prep is required. ...

How do I make a 'box and whisker plot' graph in Microsoft Excel?
I am in Year 12 and am doing a stats assignment. The project states that i MUST insert a box and whisker plot for some data, but i don't know how to do this. Does anybody know? Hi, Here are some sites on the topic of stats charting not just box and whisker. http://peltiertech.com/Excel/Charts/statscharts.html http://www.processtrends.com/toc_statistical_charts.htm http://tushar-mehta.com/publish_train/data_analysis/16.htm http://people.stfx.ca/bliengme/ExcelTips.htm Cheers Andy -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info "Year 12 student who needs help" &...

I've got a formula for stones and pounds
Hello, I've got a column that displays a series of weights in stones & pounds (both in the one cell). How do I get a chart to recognise and display in the same format? Regards, mikelenno What is the format of the cells with stone & pounds It is best to enter such values a 10 3/14 and format the cells with # ??/14 best wishes from one who is INT(275,14) stone & MOD(250,14) lbs -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from email "mikelenno" <mikelenno@discussions.microsoft.com> wrote in message news:5AD608FA-5367-4CED-AD76-1F54228EFDBA...

Printing Multiple Receipts at a Time From Journal
Hey guys, Is there a way to print multiple journaled receipts at a time? Say all receipts for a batch or by date or other criteria? Thanks Tom, Not that I've seen. -- = Get Secure! - www.microsoft.com/security You must be using Outlook Express or some other type of newsgroup reader to see and download the file attachment. If you are not using a reader, follow the link below to setup Outlook Express. Click on "Open with newsreader" under the MS Retail Management System on the right. http://tinyurl.com/75bgz ========== "Tom Bombadill" <Genius_pos...

SFO Stops working after IP Change
Hi, Last week I changed the subnet our network is one, so the IP address of the CRM Server and Exchange server have changed. Since then some of the users are having trouble with the Sales for Outlook plug in. It happens on my machine as well. When I start Outlook I get this message: --------------------------- Microsoft CRM --------------------------- There is a problem communicating with the Microsoft CRM server. The server might be unavailable. Try again later. If the problem persists, contact your system administrator. --------------------------- OK --------------------------- I've ...

How do I export my emails and folders from Outlook to Thunderbird
I'm trying to export my email from and all personal folders from Outlook to Thunderbird. Any help would be appreciated. Thanks, Sam ...

I get COMException while exporting chart on IIS 6.0.
I have this code that works perfectly on my development machine when I deployed it at customer site it gets exception. Here is the error and my code: thanks error ========== Exception from HRESULT: 0x800A03EC. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC. Source Error: An unhandled exception was generated during the execution of the c...

why do changes only save locally on networked excel file?
why do changes only save locally on networked excel file? ...

Excel problem #3
I am attaching an excel file where i have a problem In the file are 2 sheets, Main & second I want to get data from second sheet to the main sheet by a formula by which the amount in the total column will be posted in the second sheet falling under various dates. I have done for 6 sept 2003 by way of example I do not know any formula by which i can do this automatically Please help me Attachment filename: example.xls Download attachment: http://www.excelforum.com/attachment.php?postid=444742 --- Message posted from http://www.ExcelForum.com/ Hi one way: ...

Excel formulation to automate values
Hi there, I have a little problem on arranging a small multi-worksheet excel here. Let me explain in a short way then give some details on it. I am trying to make an offers recordsheet which has two worksheets in it. One for products(and their base prices) and an offer sheet. I would like to use a bit dynamic data here. So when I type the name of the product excel would give me the price from other worksheet. in details; Prices worksheet is something like: A B 1 Product BasePrice 2 mouse 5 3 keyboard 8 4 ... And the ...

Removing hidden mailto:s from Excel?
I received a spreadsheet attachment yesterday and found a mailto:(my address) embedded in a cell under a text string. It was evident in a tooltip that appeared when cell was hovered-over. I told the sender who now says that many of her spreadsheets - used to handle group memberships - have such hidden addresses. What terms would she use to search for these pests, either in My Docs or on opening each sheet? ...

Using Excel in Mac office 2004 with Microsoft/Mac 2008:Analysis toolpack
Although I am disappointed with Office 2008 for Mac because of the absent of Analysis toolpack, I figured things out quite recently that I can still install my Mac office 2004 and use the excel package that contains the Analysis tool pack. How? ...... let me show you: 1. Insert your CD for Mac office 2004 2. When it open on your desk top, two options will be given to you to download the software (a) Office set-up assistant, and (b) Microsoft office 2004. 3. CHOOSE MICROSOFT OFFICE 2004 (Drag the icon onto your desk top) and it will start to run/download. 4. When done, this will appear as ...

Printing Word and excel documents via excel vba
I have a document that has some Excel and some word content i would like to use excel vba to print both a page from word and then a page from excel. I know how to select and open the word document, however i cant find any code to print page X from word. basically i need to: print page 1 of c:\xx\document1.doc print page1 of sheet1 of c:\yy\excelwkbk1.xls print page 2 of c:\xx\document1.doc print page2 of sheet1 of c:\yy\excelwkbk1.xls and so on it will require moving between word and excel - the excel bit i get, but getting back to excel from word, and printing out in word is slightly more...

force excel to run in only one process excel.exe
force excel to run in only one process excel.exe, excel seems to want to make multiple excel.exe loaded into memory which causes mysheet.copy to fail so i have to close out the xls, kill all running excel.exe, then run the xls again and the macro works. i only have to do this when i am actively debugging a lot. if i just run my macro w/o opening the vba debugger, i can run it as much as i want, but if i run with break points it crashes a lot because of multiple excel.exe loaded into memory. perhaps there is a way i can force excel to only load one excel.exe? Daniel, Are you using Automatio...

Using Excel spreadsheet as input to Access
Hello, I posted this in the New Users forum but only got one answer, so thought I'd try here as well. Like so many others, I am an Excel newbie. I was a mainframe COBO programmer in another life, but that was a few years back My manager would like me to write an app that will take tracking dat from an existing Excel spreadsheet (generated by our system) but onl use a select handful of columns as input to a new Access database tha I will create. I'm guessing that I can either a) create a new edited spreadsheet to b used as input to the Access database or b) use the Import wiza...

Excel not displaying German characters correctly.
This is a real puzzler. Has our entire office and IT department stumped. We have two machines (M1 / M2) which are equal spec/ operating system, applications, versions, etc... The only difference that we can see between the two machines is that one (M1) has Internet Explorer encoding set to "UTF-8" with "Automatic" selected. The other (M2) has "Western European ISO" with no automatic selected. Now, when the machines log into a web application and choose to download a German Excel file, M1 and M2 get the file correctly if they have their encoding settings...

MS Excel Paste Special>Paste All
Using MS Excel 2003 Paste Special> Paste All, doesnt quite paste the 'Column Widths'. Am I always required to do the two step dance, Paste Special> Column Widths and Paste Special>All. >>Am I always required to do the two step dance Yes<g>. -- Jim "Excel User" <Excel User@discussions.microsoft.com> wrote in message news:5D34ED9D-5BD6-43AD-8773-1EB7229309B2@microsoft.com... | Using MS Excel 2003 | | Paste Special> Paste All, doesnt quite paste the 'Column Widths'. Am I | always required to do the two step dance, Paste Special> ...

Time Delayed Response to MsgBox
I have a several "research" files that I set up to run a macro as soon as a file is opened. In each case the macro retrieves and summarizes a bunch of data taking several minutes to execute. I'm setting up a "master" file with a simple macro that will open and close each of the "research" files sequentially so I can run the series of reports without being at the computer for hours. There are times where I want to open a "research" file to review the data but not execute the macro. I'd like to add a MsgBox that prompts the user t...

Count on cell for each time it is changed
I would like to count the number of times a cell has been amended/ changed e.g cell b2 has the word red it it, in cell c2 i would like a counter for everytime the cell in b2 has changed, at the end of the day you get final number. Is this at all possible? Jelinek, You can do it by putting the following VBA macro in your sheet: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$B$2" Then Cells(2, 3) = Cells(2, 3) + 1 End If End Sub Art "Jelinek" wrote: > I would like to count the number of times a cell has bee...

How can I keep track of when (date and time) data is entered into.
I am trying to create a spreadsheet for a high school class. I need to be able to track when a student has entered data into specific cells of the spreadsheet. Any ideas? In the code behind the worksheet, enter (eg) Private Sub Worksheet_Change(ByVal Target As Range) Cells(1, 1).Value = Now() End Sub This will enter in Cell A1 the date and time at which any entry is made in that worksheet. If you need the location of the time-stamp to vary according to which cell is changed then you can test the value of Target and vary the destination cell accordingly. -- Return email address is n...

Run-time error 1004
I am using Excel 97 on NT and have a command button on a sheet to whic I attached a macro for copying the sheet to a new workbook, deletin specific columns and other unnecessary info, and saving the new book t a network drive under a name with today's date for emailing to anothe area. When I perform the function manually everything works beautifully bu when I attempt to execute the macro I get the following error "Run-time error '1004': Copy method of worksheet class failed". when use the Debug button, VBA highlights Sheets("Daily").Copy as th culprit. Macro f...