For some reason I am unable to get this part of my code correct. I am using the SQL Replace expression, and when doing so it changes the format of the date it pulls in from yyyy-mm-dd to mm/dd/yyyy. I do not want this to happen as my query will not run with this type of input. I formatted the column in my table as a Date yyyy-mm-dd format, but that does not make a difference.
I have tried to used Date( dmgt![date_1]), "yyyy-mm-dd" but I get the error "expected: end of statement
Anyone have advice on how I can keep my formatting when using replace ?
Code:
Function ReRun()
DoCmd.SetWarnings False
Dim db As Database
Dim rs As Recordset
Dim useSQL As QueryDef
Dim srtdte As String
Set db = CurrentDb
Set dmgt = db.OpenRecordset("dateTable", dbOpenTable)
Set useSQL = db.QueryDefs("Vol_baseline")
DoCmd.runSQL "Delete*From [VolHistory]"
'Asign the date for the query, using the field
srtdte = dmgt![date_1]
useSQL.SQL = Replace(useSQL.SQL, "[StartDate]", srtdte)
'Run query here
DoCmd.OpenQuery "Vol_baseline", acViewNormal, acEdit
'Append query results into results table
db.Execute " INSERT INTO VolHistory " & " SELECT * " & " FROM Vol_baseline;"
useSQL.SQL = Replace(useSQL.SQL, srtdte, "[StartDate]")
For Each qry In CurrentDb.QueryDefs
On Error Resume Next
DoCmd.Close acQuery, qry.Name, acSaveYes
Next
Call DoCmd.TransferSpreadsheet(acExport, _
acSpreadsheetTypeExcel12, "VolHistory", strExcelPath, _
False, "Vol_History")
DoCmd.SetWarnings True
End Function