Docmd.transfertext using queryname
I am trying to export only specific data from a table to a CSV file.
If I export the entire table, it exports fine, but if I try to export only the selected data, nothing happens. I am using queryname for the exported data. I am not getting any error messages, so I don’t know what is wrong.
Any help is greatly appreciated.
Ok, so far my code looks like this.
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String, strQ As String
Dim Path As String
Dim CustomerId As String
Path = Me.TxFilePath.Value
CustomerId = Me.OpenArgs
Set dbs = CurrentDb
strSQL = "Select table.*" & _
"From table" & _
"Where table.[name] = 'CustomerId';"
Set qdf = dbs.CreateQueryDef("strQ", strSQL)
MsgBox CustomerId, vbOKOnly + vbInformation, "Export"
Set qdf = Nothing
DoCmd.TransferText acExportDelim, , strQ, Path, True
dbs.QueryDefs.Delete strQ
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
End Sub
+3
source to share
1 answer
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String, strQ As String
Dim Path As String
Dim CustomerId As Integer
Path = Me.TxFilePath.Value
CustomerId = CInt(Me.OpenArgs)
strSQL = "Select *" _
& " From Table" _
& " Where Name = " & CustomerId & ""
Set dbs = CurrentDb
Set dbs = CurrentDb()
Set qdf = dbs.CreateQueryDef("strQ", strSQL)
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
DoCmd.TransferText acExportDelim, , "strQ", Path, True
DoCmd.DeleteObject acQuery, "strQ"
+2
source to share