Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / October 2004

Tip: Looking for answers? Try searching our database.

Exporting a Dynamic Query w/ VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Meek - 04 Oct 2004 18:20 GMT
I'm looking to create a macro/code to run a query, export
the data to an Excel file, increment the query criteria
automatically, run the updated query, export the new
results to a new excel file, etc. until the end of the
incrementations. Please bear with me as I rarely work with
VBA and this is my first Access venture.

It comes down to I'm not sure how to edit or add queries
from VBA. I was planning a For loop, corresponding to an
array containing the strings I want to update the query to
use in each sucessive increment.

For simplicity I'll include a part of my psuedocode,
the "QUERYX =" part is where I fall short. Currently I
have how the SQL WHERE would be done w/ array variables.

For intCounterA = 1 to 3
QUERYX = WHERE `GPH 2001`.PER = astrPerCounter
(intCounterA) AND `GPH 2001`.EDATE >= alngStartDate
(intCounterA) AND `GPH 2001`.EDATE <= alngEndDate
(intCounterA)

strFileName = "SpreadSheet" + str(intCounterA) + ".xls"
DoCmd.TransferSpreadsheet acExport, 8, QUERYX, strFileName
next

If need be I'll settle for creating a whole new query in
VBA running it to export the data and then deleteing it,
only to repeat the process for each query I need to run.

Any help for a young fool like me would be greatly
appreciated.
Roger Carlson - 04 Oct 2004 20:07 GMT
On my website (www.rogersaccesslibrary.com) is a small Access sample
database called "CreateQueries2.mdb" which shows how to programmatically
create your queries.

Signature

--Roger Carlson
 Access Database Samples: www.rogersaccesslibrary.com
 Want answers to your Access questions in your Email?
 Free subscription:
 http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

> I'm looking to create a macro/code to run a query, export
> the data to an Excel file, increment the query criteria
[quoted text clipped - 28 lines]
> Any help for a young fool like me would be greatly
> appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.