Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 29th, 2005, 01:12 AM
Authorized User
 
Join Date: Mar 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending data from Access to Excel

As my username suggests,I'm a novice programmer. I want to write a code which enables me to send data from a number of queries in MS Access into an MS Excel spreadsheet in one go. The code should be written within MS access in VBA.If its not possible then, even a VB form would do. Please help....

 
Old March 29th, 2005, 12:35 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You will want to set up 1 or more variables which will be used to keep track of where you are in the process, such as an incrementable row counter and one for the column. (Long integers “Dim x As Long” would be a good variable-type choice for that.)

After opening 1 or more recordsets, loop through that/those recordset(s), filling in the Excel file using the row and column counters to determine where to put the data. (You will need to open Excel through CreateObject() or GetObject() [see VBA help for how to do that], and use the available methods to open the target spreadsheet.)

Alternatively, you can export the results of a query to excel through the processes available on the File menu of Access.

What you can do with these two methods is different—they each have their strengths and weaknesses.
 
Old March 30th, 2005, 04:28 PM
Authorized User
 
Join Date: Mar 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply Brian. I tried using the 'Export' and 'Analyze it with Microsoft Excel' but I have to select each query and export it. I want all the queries to be exported at one time. I am very new to programming and couldnt understand your reply(the first part) properly. Can you please code a little part(opening recordsets and loops) so that I can understand it easily??? Thanks in advance!

 
Old March 30th, 2005, 04:48 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

One way to learn the innards of Access programming with VBA is to create macros that do what you want, then convert them to VBA and have a look at how the task was done.

That is one thing I would do in your case. Since you can accomplish what you want one-at-a-time from the menu system, you should be able to create a macro that does the same thing.

Having done that, you can convert the macro to VBA to see how to set that sort of thing up in code. (That is not a step to facilitate what you are doing, since, if the macro does the job “you’re there!” so to speak.)

One advantage to converting to VBA though, is that you can add error handling, which will allow you to step over a 'stumble,' and will make it so that you can include notification on the screen of errors or progress.
 
Old April 1st, 2005, 10:48 PM
Authorized User
 
Join Date: Mar 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Thank you soo much Brain!!!That works!!!








Similar Threads
Thread Thread Starter Forum Replies Last Post
Transfer data from Excel to Access JezLisle Excel VBA 0 December 13th, 2007 01:25 PM
Access data to Excel Template Hamerw Access VBA 1 November 22nd, 2006 12:38 AM
Data from excel to access Vision G Access 3 June 14th, 2006 09:05 AM
Converting excel data to Access using excel VBA ShaileshShinde VB Databases Basics 1 April 26th, 2006 07:57 AM
retrieving data in excel from access. yesilkalem Access 1 May 25th, 2004 04:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.