RickHunter84
Registered User.
- Local time
- Yesterday, 22:34
- Joined
- Dec 28, 2019
- Messages
- 85
hello friends,
I need your help to spot an issue that I've tried to figure out for at least 2 hours. Im trying to export a query to a csv file based on a criteria. The code works fine until it reached the parameter to filter the query, see code below:
The line that is causing the issue is qdf.Parameters("[DS]").Value = searchCriteria - i've checked the Query and the field does exist as DS. Not sure why access is telling me that is not part of the collection.
Any feedback will be greatly appreciated.
thank you in advance.
I need your help to spot an issue that I've tried to figure out for at least 2 hours. Im trying to export a query to a csv file based on a criteria. The code works fine until it reached the parameter to filter the query, see code below:
Code:
Public Function ExportQueryToCSV(searchCriteria As String)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As QueryDef
Dim filePath As String
Dim fileName As String
Const queryName As String = "DisposetQ"
Const exportFolder As String = "C:\Users\Megaman\CSVAccessSearch\"
fileName = "PNstoSearch.csv"
' Combine the folder and file path
filePath = exportFolder & fileName
' Open the query
Set db = CurrentDb
Set qdf = db.QueryDefs(queryName)
qdf.Parameters("[DS]").Value = searchCriteria
Set rst = qdf.OpenRecordset()
If Not rst.EOF Then
DoCmd.TransferText acExportDelim, , queryName, filePath, True
MsgBox "Query results exported to " & filePath, vbInformation, "Export Successful"
Else
MsgBox "No matching records found.", vbInformation, "Export Aborted"
End If
Set rst = Nothing
Set qdf = Nothing
Set db = Nothing
End Function
The line that is causing the issue is qdf.Parameters("[DS]").Value = searchCriteria - i've checked the Query and the field does exist as DS. Not sure why access is telling me that is not part of the collection.
Any feedback will be greatly appreciated.
thank you in advance.