you can change the query to be exported via user input, by using an
InputBox() function in your code, as
Public Sub isExport()
On Error GoTo isExport_Err
Dim strName As String
strName = InputBox("Enter the query name.")
DoCmd.TransferText acExportDelim, , strName, "C:\" & strName & ".txt"
MsgBox "Query export is complete."
isExport_Exit:
Exit Sub
isExport_Err:
Select Case Err.Number
Case 3011 ' invalid query name
MsgBox "The query name you entered is not valid."
Resume isExport_Exit
Case 2495 ' no object name entered
Resume isExport_Exit
Case Else
MsgBox Err.Number & " " & Err.Description, , "isExport()"
Resume isExport_Exit
End Select
End Sub
your user has to know the exact name of the query, and enter it correctly.
to avoid that issue, you might want to obtain the user's query selection by
using a form with an unbound combobox or listbox that lists all the query
names. you could use a table listing all the query names as the combobox's
RowSource, or you could build the RowSource dynamically by looping through
all the queries in the QueryDefs collection.
hth