473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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.OpenRecordSe t ("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 3354
JConsulting
603 Recognized Expert Contributor
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.OpenRecordSe t ("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
6505
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 Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to...
9
4390
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 the microsoft HTML workshop utility, lets call it c:\path\help.chm. My question is how do you launch it from the GUI? What logic do I put behind...
4
3335
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 cmd.Cmd but I would also like to get the man-page-like help for classes and functions. Does anyone know how to do that? Thanks. Sarir
6
2998
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 an html authoring tool to help you accomplish? 2. What do you expect from online help for a html authoring tool? 3. What audience do you think...
5
2975
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 <<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>> <html>
0
1492
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. Create two button_click events with the following code in it For button1 Help.ShowHelpIndex(Me, "C:\Temp\File1 mspaint.chm")
3
2430
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 --------------- Python 2.3.3 (#51, Dec 18 2003, 20:22:39) on win32 Type "help", "copyright", "credits" or "license" for more information. >>>...
3
2021
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 far so good - when I press F1, I get HTML Help popping up with my Help file. This is good but I've been requested to make Help pop up when the user...
1
9503
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 of the best way to call it. I have tried private void helpaHelpToolStripMenuItem_Click(object sender, EventArgs e) {
0
2862
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 calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in...
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.