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


Similar Artilces:

Contacts export display X400 not SMTP
Hi all, I'm not sure if this behavior is by default or not, but when my users try to export their contacts to an Excel file, any internal (domain) contacts show the X400 address rather than the SMTP address. Is there a way to change this? I've read some about VB scripts with CDO or something, but hoping there is an alternate way. Thanks Mike -- what version Exchange? -- Susan Conkey [MVP] "Mike W." <wallmr_snowpam@gmailDOTC0M> wrote in message news:iQ72h.553254$Pi2.240974@fe08.news.easynews.com... > Hi all, > > I'm not sure if this behavio...

Excel 2003 Inserting current date
I wish to create a spreadsheet that whenever data is entered in a row/column, the actual date is entered automatically in a date column. I do not want the date to be overridden. Mark Right-click your sheet tab and "View Code". Copy/paste this event code in that sheet module. Enter anything in any cell in column A and B will get a static date. Private Sub Worksheet_Change(ByVal Target As Excel.Range) 'Col B time will not change if data in Col A is edited On Error GoTo enditall Application.EnableEvents = False If Target.Cells.Column = 1 Then n = Target.Row ...

Export to XML exports single row only
What I did: On XML source panel of Excel 2007 added XML map, mapped to columns using ranges (i. e. A1:A1825), selected “Export” from “Developer” tab in the ribbon. Result: Output XML file contains only one record (first row from the worksheet) I’ve done this numerous times in Excel 2003 with no problem. What happens?? Please help! Thanks, Eugene ...

spell check no longer working
whenever I send an e-mail my spell check says that an error had occurred with spell check and when I send, it says that spell check was halted-do you still want to send. I can't figure out what's going on, it's been doing it for awhile now, but it used to work fine Please help Thank you!!! ...

Access vs Excel
I wanted to get the opinion of both the excel and access group on this subject. We currently have an ERP but is lacking in some aspects. In order to get around the shortcomings, I have an user that is very proficient with excel. He has made spreadsheets that access the information out of our ERP and mimics some of it's functions. He is using excel to store information and has created interfaces for users to enter in data. My question is, should we continue using excel to do this. We have hundreds of excel files that get created with information everywhere. OR should we start using acc...

Export / Import Security
Ok, so I have setup my test environment again. Now I have to create security all over from scratch to define what will be used in production. Is there a way to export from the test environment and then import it into the newly upgraded installation? In both cases security has been/will be completely removed from the 8.0 install (restored on new server) before being upgraded to version 10. Dear, Security will be upgraded upon upgrading GP from GP 8.0 SP5 to GP 10.0. Converting the Security structure from GP 8.0 to 10.0 will not be an easy task. Regards, -- Mohammad R. Daoud MCP, MCBM...

Excel to Access
Does anyone know how to take an Excel spreadsheet and merge it into an existing Access database? Thank you. ...

lost Excel data!
I've just deleted some important data from an Excel sheet having moved it to another workbook. Unfortunately I closed the new workbook without saving and I can't find the data! I've not got a backup of the old workbook and the data is not on the clipboard. Is there any way of recovering it? thanks MrBen AFAIK, NO. We all gotta learn sometime (to make backups) -- Don Guillett SalesAid Software donaldb@281.com "MrBen" <anonymous@discussions.microsoft.com> wrote in message news:2305c01c45e8d$7842a610$a601280a@phx.gbl... > I've just deleted some importa...

Exporting Sent Email Addresses from Entourage
Version: 2004 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC Hello! I'm trying to export email addresses from an employee's Entourage, but would like to include email addresses in his "Sent Items" folder. Is there a way to export these email addresses aside from exporting the "MBOX" file, which has all the email content as well? Thanks in advance! On 3/12/08 8:49 AM, in article ee9381d.-1@webcrossing.caR9absDaxw, "Quinlisk@officeformac.com" <Quinlisk@officeformac.com> wrote: > I'm trying to export email addresses from an emplo...

Fonts get size 1 and can't be changed after a procedure
Hi, I have been using code to loop for each chtobj in a worksheet to set font size right etc. Sometimes an error occur and the size become 1 pt. I can live with that once or so, but I can't change the FONT BACK neither with code nor from excel chart GUI. No code are running in background during this of cource, I try even to change the font from Excel GUI with macro switched off. It can only be solved with building a new chartobject... Have any of you got this error, any knowing why it occure and what I can do about it? I thougt it was because some of the charts had no values or s...

Export item ID?
Hi there. Having resolved my previous EMS Data import issues, I have now moved on to more complicated things (importing supplier lists, aliases etc). However, these operations require the item ID for each item - something I don't have. Is there some way I can export these from the database so I know what item ID corresponds to each item. I have run a query in Administrator (select itemlookupcode, ID from item) which tells me this, but I haven't worked out how to export this out to a spreadsheet. Any help would be appreciated, cheers After running your query goto File menu and Export....

Excel XML
Hi all, Newbie here. I have an application that outputs Excel XML, auto-emailing to a distribution list. This ended up working wonderfully, users can just click on the attachment in the email and the file opens up in a great Excel spreadsheet for them. Prior, we would only export delimited text files, which had to be imported to Excel. Not hard, just extra steps. However, I have TWO users that are on Macs. Their version of Excel on the Mac cannot handle XML or read it. I've been Googling for days now and have only found years old postings about how Mac's Excel left this f...

Exporting email in Outlook Express
I am unable to export all emails in Outlook Express. First it had an error message mentioning MAPI so i followed the instructions on Microsoft Knowledge Base to install Windows Messaging - now when i try to export the following error message is: MAPISP32 caused an invalid page fault in module KERNEL32.DLL at 0187:bff7b9a6. Does anyone know what this means? tania jackson <tania@realtime-bs.com> wrote: > I am unable to export all emails in Outlook Express. Ask in an Outlook Express newsgroup. -- Brian Tillman Smiths Aerospace 3290 Patterson Ave. SE, MS 1B3 Grand Rapid...

Excel 2002, now 2007
I was previously using Excel 2002 and decided to buy Home and Student non-commercial 2007. I am having problems converting my 2002 files to 2007 and also do not seem to be able to upload the files thru 2007. I'm thinking because it is non-commercial, Excel 2007 non-c does not want you to upload to a website. Okay, can I purchase an upgrade of just Excel 2007 so that I can convert files and upload to my website? If I could I would go back to using my 2002 version I tried loading it again but the computer says it does not find a MS product to upgrade... Thanks...Nancy ...

Problem with Excel 2007
Hi Everyone, It is my first time working on Excel 2007. I was working on a project which I started on Excel 2003, I opened another project for reference and when I returned to the first project all sheets disappeared. The only accessible buttons on the toolbar are the Macro buttons. All macros are still there and sheet names in the VBA are still there. Did I loose my work? Thanks to all albertmb;657269 Wrote: > Hi Everyone, It is my first time working on Excel 2007. I was working on a > project which I started on Excel 2003, I opened another project for referen...

How to create "frames" in Excel 2003?
Hi all, Is there a way to create frames in Excel like one can do for webpages? For example if I split my sheet vertically, I want a frame on the left side which has "links" that if I click them change the sheet I'm viewing on the right side. Thank you! Anyone? ...

Exporting to Powerpoint
I have a small table in Excel that I am trying to export to PowerPoint, for some inexplicable reason one column was always missing even though it was specified in the range which the Macro is supposed to export. My manager is the only was able to see the value in that column and no other can replicate his success. Do you know any reason for this? We are all looking at the exact same file, why could he see something that the rest of us cannot? Tao, Why don't you simply copy and paste the whole table into a Powerpoin slide? Joh -- Message posted from http://www.ExcelForum.com...

Getting this message when i startup excel 2003
Getting this message when i startup Excel 2003, C:\Program Files\Adobe\Acrobat 5.0\pdfmakerA.xla could not be found, i have Acrobat 6 on my computer, i have tried the repair and it still comes up, i have unistalled from add and remove, then reinstalled office 2003 but it still comes up when i start Excel Go to Tools-->Add-ins, and uncheck it. ******************* ~Anne Troy www.OfficeArticles.com www.MyExpertsOnline.com "Brian" <Brian@discussions.microsoft.com> wrote in message news:7792B9F9-2A5F-471B-A6B4-8151485F5D5F@microsoft.com... > Getting this message whe...

Cashier Time Clock Report error ( -2147467259 )Conversion failed
Cashier Time Clock Report error ( -2147467259 )Conversion failed when converting datetime from character string. I am using RMS 2.0. I am trying to run the Cashier Time clock report for last two week pay periods 2/14/2008 to 2/17/2008. I read post from that you change couple of numbers in Active reports and you could fix a problem, but I was unable to find that post. ...

Free/busy time for a user shows no information
While trying to view someone's free/busy information when scheduling a meeting in the Calendar, their information shows gray slashes and says No information is available. We are all on the same Outlook Exchange Server. Please assist Try opening Outlook using the \cleanfreebusy switch on that users computer. See KB296192 "Keighla" <anonymous@discussions.microsoft.com> wrote in message news:d22301c439d1$98fc34b0$a401280a@phx.gbl... > While trying to view someone's free/busy information when > scheduling a meeting in the Calendar, their information > shows...

Excel 2000 Security patch crashes Excel
I recently upgraded my computer, although I am still using Excel 2000. As part of the upgrade, I decided to be good and updated all the available service patches for Excel 2000. I later tried opening a file that I have created and work with extensively - and Excel crashed. Something that never happened before. I tried opening the file on a different computer - and it worked just fine. So I began debugging to find what the problem was - I stripped out all the VBA, and then I stripped out the worksheets one-by-one, until I came upon the root of the problem. I had a picture inserted, with a hyper...

Export Image Package
I have an access application that has stored .JPG images within the database as a "Package". How can I export the image back to a normal .jpg file so that it can be read by a normal (non ole server) imaging application? ...

Export registry key
Hi, Is there an API to Export and Extract a registry key in a text format ? I need to simulate the operation that is done by the user of exporting a key (and creating a .reg file in a text format). I do not want to use RegSaveKey/RegRestorekey which work in a binary format. Yoav. I believe you will have to do this yourself. There is no Automation or exported function interface to RegEdit, and that .Reg file concept is a feature of that program. However, it shouldn't be terribly difficult to do this, using RegEnumKeyEx and RegEnumValue or the CRegKey class, use a CStdioFile object...

Visual Basic macros in Excel
I have some files in Excel with Visual Basic macros. I often modify the file, then delete the macros to send to other users. Whenever I open this new file, Excel still says that it contains macros, which it does not. Can anything be done to stop this from happening? Go to google.com and search groups for this--e.g. Excel macros erased or deleted , this topic has come up many times. It involves going into VBE and deleting some stuff manually. "Glenn Wohl" <gwohl@att.com> wrote in message news:018b01c3a48e$ca8549f0$a301280a@phx.gbl... > I have some files in Excel wi...

Excel trademark
Do I need to use the "TM" after the name Excel when mentioning this product in product briefs? I make no claim to being a legal expert. However, it appears that the word "Excel" is not trademarked; see http://www.microsoft.com/library/toolbar/3.0/trademarks/en-us.mspx However, when I approached Microsoft many years ago prior to publishing my first book they wanted me to use the phase "Microsoft Excel" everywhere. We agreed I would do that the first time in each chapter. Note the Microsoft is registered. So you use Microsoft� Excel. -- Bernard V Liengme www...