Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA DoCmd.TransferText - exporting query to .csv with user defined file path

Tags:

vba

Currently my code is this:

Dim testSQL As String
Dim qd As DAO.QueryDef

testSQL = "SELECT * FROM qryExample WHERE exampleID IN (" & strExampleIDList & ")"
Set qd = db.CreateQueryDef("tmpExport", testSQL)
DoCmd.TransferText acExportDelim, , "tmpExport", "C:\export.csv"
db.QueryDefs.Delete "tmpExport"

How do I change the "C:\export.csv" part so that the user is able to define the file path and the file name?

Thanks.

like image 283
user1844098 Avatar asked Feb 05 '13 04:02

user1844098


1 Answers

Assuming you want the user to be prompted for input, and then use that input in your TransferText call, try this:

Dim UserInput As String
UserInput  = InputBox("Please enter the file path.", "I WANT A VALUE!") 
DoCmd.TransferText acExportDelim, , "tmpExport", UserInput  

There are other approaches out there, but this is perhaps the easiest to implement.

Good luck.

like image 84
sgeddes Avatar answered Oct 01 '22 03:10

sgeddes