OutputTo File

K

Kris

Using the OutputTo action in a Macro, I want it to prompt me for the
Output File name but already have the location preselected.

For example, I always want the file saved in c:\documents\kris\

If I put that in the Output File name, it errs on me. It would be
nice if I didn't have to choose the path everytime. I need the name
the file the current date.

I'm using Access 2007
 
K

Ken Sheridan

I don't know about a macro, but its easily done with VBA. For example to
export a query to a text file add a procedure along these lines to a standard
module in the database:

Public Sub OutputToTextFile(strQuery As String, _
strFolder As String, _
strFile As String)

DoCmd.OutputTo acOutputQuery, strQuery, _
acFormatTXT, strFolder & "\" & strFile

End Sub

and call it like so:

Const conFOLDER = "C:\Users\Kris\Documents"
Dim strFile As String

strFile = InputBox("Enter File name:", "Output To Text File") & _
Format(VBA.Date, "yyyy-mm-dd") & ".txt"

OutputToTextFile "YourQueryName", conFOLDER, strFile

This would give the file whatever name you enter in the input box followed
by the current date in the ISO format yyyy-mm-dd and a .txt extension, e.g.

MyFile2008-04-12.txt

if the user had entered MyFile at the prompt.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top