I wrote the below Sub
to run a few Make-table
queries, of which some use a parameter Some_date
Sub run_query(queryName As String, Optional Some_date As Date)
Form_Select_input.logProgress queryName
Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.QueryDefs(queryName)
On Error Resume Next
qdf!Date_after = Date_after
On Error GoTo 0
qdf.Execute
Set qdf = Nothing
End Sub
A typical query looks like
PARAMETERS Some_date DateTime;
SELECT Some_field
, Other_field
INTO Some_Target
FROM Some_Source
LEFT JOIN Other_Source
ON Some_Source.key = Other_Source.key
where Some_Source.Transaction_Date > [Some_date];
Now this works the first time I run the queries, but the second time, gives an error the tables already exist, so I would like to write something like
Sub run_query(queryName As String, Optional Some_date As Date)
Form_Select_input.logProgress queryName
Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.QueryDefs(queryName)
On Error Resume Next
DoCmd.DeleteObject acTable, qdf.Destination ' At first execution, the destination does not exist, but we resume next
qdf!Date_after = Date_after ' For some queries, the parameter does not exist, but we resume next
On Error GoTo 0
qdf.Execute
Set qdf = Nothing
End Sub
Please help me replacing qdf.Destination
with something that exists.