I have a file that I bring into Access. Then I execute an SQL query on it and output the results. I've got it working in the following manner:
Code:
Function Proc_daymacro()
On Error GoTo Proc_daymacro_Err
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, "3days"
DoCmd.TransferText acImportDelim, "3days Import Specification", "3days", "3days.csv", True, ""
DoCmd.OpenQuery "All3", acViewNormal, acReadOnly
DoCmd.TransferText acExportFixed, "3daysExportSpecification", "All3", "x3rd_day_17003.txt", True, ""
DoCmd.SetWarnings True
Proc_daymacro_Exit:
Exit Function
Proc_daymacro_Err:
MsgBox Error$
Resume Proc_daymacro_Exit
End Function
and the SQL query, All3, looks like this:
Code:
SELECT Serial
FROM 3days
WHERE date>=#12/2/2013#
GROUP BY Serial
HAVING count(*)=3;
Having got the above working, I would like to prompt the user for the date specified in the SQL query and dynamically insert it.
In An attempt to just get it working with a fixed date, this is the best I could come up with and it doesn't work:
Code:
Function Proc_daymacro2()
On Error GoTo Proc_daymacro_Err
Dim strSQL As String
strSQL = "SELECT Serial " & _
"FROM 3days " & _
"WHERE Date >= #12/2/2013# " & _
"GROUP BY Serial " & _
"HAVING count(*)=3"
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, "3days"
DoCmd.TransferText acImportDelim, "3days Import Specification", "3days", "3days.csv", True, ""
DoCmd.RunSQL strSQL
DoCmd.TransferText acExportFixed, "3daysExportSpecification", "All3", "x3rd_day_17003.txt", True, ""
DoCmd.SetWarnings True
Proc_daymacro_Exit:
Exit Function
Proc_daymacro_Err:
MsgBox Error$
Resume Proc_daymacro_Exit
End Function
I just found out that "DoCmd.RunSQL" can only be used if you are doing an INSERT, DELETE etc because it doesn't return a result. However, I cannot find out how to make it work.
I am grateful for any input