473,378 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Access Table Export to Excel

283 100+
Hello,

I am having some trouble getting a table to open up as an Excel file after you press a button on a form. So far I have part of the code working where it will open up the Excel file but it will only display the headers and no information. I know which line of the code is not working just not sure why.

Any help with this would be appreciated.

Thanks,

Slen


Here is what I have so far
Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim rs As DAO.Recordset
  3. Set db = CurrentDb
  4. Set rs = db.OpenRecordset("tbl adj and refunds", dbOpenSnapshot)
  5.  
  6. 'Start a new workbook in Excel
  7. Dim oApp As New Excel.Application
  8. Dim oBook As Excel.Workbook
  9. Dim oSheet As Excel.Worksheet
  10.  
  11. Set oBook = oApp.Workbooks.Add
  12. Set oSheet = oBook.Worksheets("Sheet1")
  13.  
  14. oApp.Visible = True
  15. oApp.UserControl = True
  16.  
  17. fldCount = rs.Fields.Count
  18. For iCol = 1 To fldCount
  19.     oSheet.Cells(1, iCol).Value = rs.Fields(iCol - 1).Name
  20. Next
  21.  
  22. '**The line below is the problem, nothing copies**
  23. oSheet.Range("A2").CopyFromRecordset rs
  24.  
  25.  
  26. 'Format the header row as bold and autofit the columns
  27. With oSheet.Range("A1").Resize(1, fldCount)
  28. .Font.Bold = True
  29. .EntireColumn.AutoFit
  30. End With
  31.  
  32.  
  33. 'Close the Database and Recordset
  34. rs.Close
  35. db.Close
  36.  
Dec 29 '11 #1
5 1672
NeoPa
32,556 Expert Mod 16PB
Have you compiled this code?

I assume line #23 is the problem and there is no error message.

You tell us very little information. I see no code that opens Excel (See Application Automation). Does Excel even open properly?
Dec 29 '11 #2
sierra7
446 Expert 256MB
Hi
The fact that your headings are copying means that the spreadsheet is opening and you have some sort of recordset.

As a shot in the dark, try a 'rs.MoveFirst' at line #21.

S7
Dec 29 '11 #3
slenish
283 100+
Hello NeoPa,

The code does execute and excel opens properly it just only shows the headers from the table and none of the information. Line 23 (oSheet.Range("A2").CopyFromRecordset rs)
is the problem because it should be setting the OpenRecordset to start copying the info at cell A2, but alas nothing...

Sierra7 - tried your suggest and no luck :D
Dec 29 '11 #4
NeoPa
32,556 Expert Mod 16PB
OK. But before I go to the trouble of setting up a test rig why don't you tell me what happens when you try it with the approach suggested in the linked article (which is the recommended way of doing it), CreateObject(Class)?
Dec 29 '11 #5
slenish
283 100+
Hi NeoPa,

Appreciate the quick response. I will try the CreateObject(class) and let you know what happens tomorrow. I dont have enough time to test it today.

Thanks,
Slen :D
Dec 29 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: tomg | last post by:
I am able to export an MS-Access table to Oracle if that table does not exist there. I would like to append data to the Oracle table, but I get the Oracle message "Error--00955 Name is already...
7
by: Keon | last post by:
Hoi, I'm using a database with alot of records in 1 table (more than 3000). If i want to export this table to excel i only get it till record 2385. Do someone know how i can solve this...
3
by: bwhite | last post by:
I have a temp table with one row of data that I need to export into Excel. I created the export to create the xls file as follows ... Dim FileName FileName = !! DoCmd.SetWarnings False...
3
by: sam | last post by:
Can you teach me how to export access file to excel file in VB.net? Thank in advance.
5
by: daicakien | last post by:
hi everybody, im developing access db. my user want to export some column of the table( in access) to Excel( he may choose from list box of form). do you have any idea about it? thanks
1
by: cmcl95 | last post by:
HI Folks, I need some help I'm trying to develop a automated way to import from a excel spsh excluding the 1st 2 rows & two out of 41 columns. I got the 1st part with range see below ...
10
Nathan H
by: Nathan H | last post by:
I am curious if this is possible to do. I have a case scenario where I need to export data from an access table into an excel spreadsheet, and have that data start on row 5. Can't do it from Excel...
2
by: wbw | last post by:
How can I rename an Access table from Excel VBA? I know <DoCmd.Rename "new_name", acTable, "old_name"> however the ending characters of the "old_name" will vary from database to database. I need to...
3
by: sarah2855 | last post by:
Hello All, I'm looking for the vb code that export an access table to specific worksheet in Excel. I tried to search see if this question was answered before here, but didn't find anything that...
1
by: Mark Niznik | last post by:
by using a mcaro, I need to transfer an access table into Excel and insert today's date in the filename.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.