|
-
Apr 23rd, 2010, 11:01 AM
#1
Thread Starter
New Member
[RESOLVED] Need help exporting data to excel 2007
Basically I'm taking data from an Access 2000 database and dumping it in Excel. Although this concept works for Excel 2003, but not Excel 2007. I'm using Vb6 for this process.
Sample Code:
'The dialog box that asks the user where to save the document or object
With CommonDialog1
.InitDir = customer_root
.DefaultExt = ".xlsx"
.Filter = "Excel Workbook (*.xlsx)|*.xlsx"
.ShowSave
.CancelError = True 'If the user clicks cancel then the program exits
the sub
End With
ExcelName = "Excel 8.0;DATABASE=" 'I've tried setting this to 12.0 but no luck.
sql = "SELECT " & NewData & " INTO [" Excel 8.0;DATABASE=C:\Test.xlsx].[12_2_2009]] " & _
" FROM NewTable " & _
" WHERE (Line < 900) OR (Line >= 900 AND Action01 = 1) ORDER BY EndStep"
Debug.Print sql
objDB.Execute sql
-
Apr 23rd, 2010, 11:04 AM
#2
Thread Starter
New Member
Re: Need help exporting data to excel 2007
There is an extra bracket in the sql statement because i edited please ignore cause its not in the original code.
-
Apr 23rd, 2010, 11:08 AM
#3
Thread Starter
New Member
Re: Need help exporting data to excel 2007
Running the above code i get this error
Error Code: 3027
Cannot update. Database or object is read-only.
it's because of the variable "ExcelName". Setting it to 12.0 gave another error about not being able to find the installable ISAM. Already googled it and went through all the scenarios provided by other experts like install the latest version of Jet and MDAC. Do you guys think vb6 understands the 4 character extension or Excel 2007 ?
-
Apr 23rd, 2010, 01:10 PM
#4
PowerPoster
Re: Need help exporting data to excel 2007
Why not dump it to Excel 2003 and just open it with 2007?
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Apr 23rd, 2010, 01:17 PM
#5
Thread Starter
New Member
Re: Need help exporting data to excel 2007
Because I need to dump over 70,000 rows of data for a report. 2003 can only handle up to 65,000 and 2007 and handle over 1,000,000 (with some registry mod). It's for work.
-
Apr 23rd, 2010, 01:24 PM
#6
Re: Need help exporting data to excel 2007
Welcome to VBForums 
You haven't shown how you set up the connection, but I suspect you are using JET, which does not know about the recent file types. What you should be using instead is ACE, which you can get via the link in my signature (another link shows examples of connection strings).
Alternatively, if Excel will be installed on the computer your code is running on, you can use Automation to work with whatever version of Excel is installed. See my tutorial (link in my signature) for details.
-
Apr 23rd, 2010, 01:27 PM
#7
Thread Starter
New Member
Re: Need help exporting data to excel 2007
Thanks for welcoming me to the forums. I'll check out the links.
-
May 12th, 2010, 09:09 AM
#8
Thread Starter
New Member
Re: Need help exporting data to excel 2007
Thanks si for the help. I was able to write the data to excel 2007, but now the other dilemma is it gives me an error when i try to open the file. Err msg: Excel cannot open " & insert file name & " the file format or file extension is not valid.
vb Code:
'The dialog box that asks the user where to save the document or object With CommonDialog1 .InitDir = customer_root .DefaultExt = ".xlsx" .Filter = "Excel Workbook (*.xlsx)|*.xlsx" .ShowSave .CancelError = True 'If the user clicks cancel then the program exits the sub End With sql = "SELECT " & NewData & " INTO [" & Excel 12.0;DATABASE & strExcelFile & "].[" & wkshCallDetail & "] " & _ " FROM NewTable " & _ " WHERE (Line < 900) OR (Line >= 900 AND Action01 = 1) ORDER BY EndStep" cnnaccess.execute sql
-
May 12th, 2010, 09:13 AM
#9
Re: Need help exporting data to excel 2007
You've got a significant typo there, I think it should be like this:
Code:
sql = "SELECT " & NewData & " INTO [Excel 12.0;DATABASE=" & strExcelFile & "].[" & wkshCallDetail & "] " & _
-
May 12th, 2010, 09:16 AM
#10
Thread Starter
New Member
Re: Need help exporting data to excel 2007
oh yea that's how it looks my bad. 
This is how it looks in debug mode
SELECT Onion,CallCounter AS [ORCA Call ID],NetworkConnect as [Network Connect],Start,EvaluatedResult,EndStep,Answer,Done,ANI,TestCase AS [Test Case],Call_Time,Data01,Time01,Data04_01,Time04_01,Data05_01,Time05_01,Audio INTO [Excel 12.0;DATABASE=C:\!Drill\_H&RBlock_CallDetailReport_20091202_TOOLaaa.xlsx].[12_2_2009] FROM NewTable WHERE (Line < 900) OR (Line >= 900 AND Action01 = 1) ORDER BY EndStep
-
May 20th, 2010, 08:57 PM
#11
Thread Starter
New Member
Re: Need help exporting data to excel 2007
It seems as if excel 2007 won't let you the above code, so i got it work with the copyfromrecordset.
-
May 21st, 2010, 07:01 AM
#12
Re: Need help exporting data to excel 2007
 Originally Posted by supeazn
Because I need to dump over 70,000 rows of data for a report. 2003 can only handle up to 65,000 and 2007 and handle over 1,000,000 (with some registry mod). It's for work.
I will suggest the same thing to you what I suggested this guy and I will leave the decision to you...
http://www.vbforums.com/showpost.php...3&postcount=13
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
May 21st, 2010, 02:43 PM
#13
Thread Starter
New Member
Re: Need help exporting data to excel 2007
Thanks for the suggestion. Because we are in the mist of converting to Office 2007 and dumping 2003 (i know it sucks). I got it to work like i said ^.
-
Jun 10th, 2010, 11:42 AM
#14
Thread Starter
New Member
Re: Need help exporting data to excel 2007
i got this to work. Please close !
-
Jun 10th, 2010, 11:46 AM
#15
Re: Need help exporting data to excel 2007
If you consider your question to be resolved then pull down the Thread Tools menu and click the Mark Thread Resolved menu item. That will let everyone know that you have your answer.
Thank you.
-
Jun 10th, 2010, 11:47 AM
#16
Thread Starter
New Member
Re: [RESOLVED] Need help exporting data to excel 2007
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|