473,402 Members | 2,072 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,402 software developers and data experts.

Help! Export a Query using a Do Loop Result (VBA Access)

Hi! I am a VBA newbie, and cant seem to proceed past my current problem.

I have a large query, where I need to output a select query based on the parameter set by the do loop. The do loop is running through locations, where there will be many records per each location set in the parameter. The output needs to go to the same file location each time and then trigger a format macro in Excel.

The bit I am stuck with is taking the do loop result and making this a parameter for the query to then successfully output??!!! Ive hit a real dead end.. My do loop below. Any help or hint would be much appreciated!! Thanks.

Function LocationOutput()

Dim db As DAO.Database
Dim myset As DAO.Recordset
Dim Location As String

Set db = CurrentDB
Set myset = db.OpenRecordSet ("Customer_Tbl")

Do Until myset.EOF
Location = myset![Location Name]

'Output query result and run macro here...

myset.MoveNext
Loop
End Function
Jul 24 '07 #1
1 3343
JConsulting
603 Expert 512MB
Hi! I am a VBA newbie, and cant seem to proceed past my current problem.

I have a large query, where I need to output a select query based on the parameter set by the do loop. The do loop is running through locations, where there will be many records per each location set in the parameter. The output needs to go to the same file location each time and then trigger a format macro in Excel.

The bit I am stuck with is taking the do loop result and making this a parameter for the query to then successfully output??!!! Ive hit a real dead end.. My do loop below. Any help or hint would be much appreciated!! Thanks.

Function LocationOutput()

Dim db As DAO.Database
Dim myset As DAO.Recordset
Dim Location As String

Set db = CurrentDB
Set myset = db.OpenRecordSet ("Customer_Tbl")

Do Until myset.EOF
Location = myset![Location Name]

'Output query result and run macro here...

myset.MoveNext
Loop
End Function

something like so will get you going

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function ExportTxt()
  3. Dim rs As dao.Recordset
  4. Dim qDf As QueryDef
  5. Dim strSQL As String
  6. Dim myLocation As String
  7. Dim myFile As Long
  8. Set rs = CurrentDb.OpenRecordset("select distinct Location from Locations;")
  9. If rs.EOF Then Exit Function
  10. rs.MoveFirst
  11. On Error Resume Next
  12. DoCmd.DeleteObject acQuery, "MyQuery"   '<--- This deletes the old temp query getting ready to make a new one
  13. myLocation = rs!Ballot_Style
  14. myFile = "C:\myfile.xxx"
  15. strSQL = "SELECT * FROM Locations WHERE Location='" & myMyLocation & "';"
  16. Set qDf = CurrentDb.CreateQueryDef("MyQuery", strSQL)
  17. DoCmd.TransferText acExportDelim, , "MyQuery", myFile, False
  18. rs.MoveNext
  19. Loop
  20. rs.Close
  21. Set rs = Nothing
  22. End Function
  23.  
  24.  
It creates a "temp" query that you use to export to whatever file name you want. you can create a variable filename to match your location or whatever.
J
Jul 31 '07 #2

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

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
0
by: Yabedabe | last post by:
Hello there, I have a strange problem (possible bug?) to display two HTML Help files at the same time. To reproduce this problem. Create a new VB.Net solution. Place two buttons on the form....
3
by: stuart_white_ | last post by:
I've just upgraded from Python 2.3.3 to Python 2.4.2, and, although the new version of Python seems to be running correctly, I can't seem access the help from the interpreter. On Python 2.3.3...
3
by: lord.zoltar | last post by:
I've managed to get a nice little chm help system written. Now I need to display it! I added a HelpProvider to my MDIParent form and set the namespace of the HelpProvider to be the help file. So...
1
by: gordon | last post by:
Hi I have an app that i have written a chm help file for. What is the best way to associate that with my help menu and the F1 key. I have added the file to the project already, just not sure...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.