By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,560 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,560 IT Pros & Developers. It's quick & easy.

Exporting to a text file

P: n/a
I have a query called qrylabels that is based on a table tblbospen. I want
to run the query from the Switchboard and also export the results from the
query to a comma separated text file called labels.txt. I know how to do
these procedures individually but I want it to be a seamless operation on
clicking a choice in the switchboard where the only intervention by the user
would be to ask them where to save the file. Can this be done using either a
macro or VBA? I'm a novice at VBA so please go gentle with me!
TIA
Tony Williams
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
This is how I would do it:

Paste the following code into a new module:

Function QandX(QryN As String, QryN2 as string fileName As String)
On Error GoTo erh
DoCmd.SetWarnings False
DoCmd.OpenQuery QryN
DoCmd.SetWarnings True
DoCmd.OutputTo acOutputQuery, QryN2, "Text Files (*.txt)", fileName,
False
xit:
DoCmd.SetWarnings True
Exit Function
erh:
MsgBox Error$
Resume xit
End Function
Then make a macro where you choose the following command:
runcode
then in the little entry box you write

QandX(x,y, y)
where x is the name of the query you are running, and
y the name ofthe query that you are outputting, and
z the filename that you want it to be.

Lastly, you include the macro in your switchboard.

Any further questions, please ask
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.693 / Virus Database: 454 - Release Date: 31/05/2004
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.693 / Virus Database: 454 - Release Date: 31/05/2004
Nov 13 '05 #2

P: n/a
Thanks I'll try that and come back to you if I get stuck if I may
Tony
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:SR********************@news.xtra.co.nz...
This is how I would do it:

Paste the following code into a new module:

Function QandX(QryN As String, QryN2 as string fileName As String)
On Error GoTo erh
DoCmd.SetWarnings False
DoCmd.OpenQuery QryN
DoCmd.SetWarnings True
DoCmd.OutputTo acOutputQuery, QryN2, "Text Files (*.txt)", fileName,
False
xit:
DoCmd.SetWarnings True
Exit Function
erh:
MsgBox Error$
Resume xit
End Function
Then make a macro where you choose the following command:
runcode
then in the little entry box you write

QandX(x,y, y)
where x is the name of the query you are running, and
y the name ofthe query that you are outputting, and
z the filename that you want it to be.

Lastly, you include the macro in your switchboard.

Any further questions, please ask
---
Please immediately let us know (by phone or return email) if (a) this email contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.693 / Virus Database: 454 - Release Date: 31/05/2004
---
Please immediately let us know (by phone or return email) if (a) this email contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.693 / Virus Database: 454 - Release Date: 31/05/2004

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.