kimmer7389
Technical User
This is what I am trying to do:
On an Access form:
1. User selects a start weekending date from a combobox
2. User Selects an end weekending date from a combobox.
3. User clicks a button to start the process.
The process runs a query in Access with the dates the user selected and overwrites data in an existing Excel file.
Below is my code. I am getting a runtime error "3075" and the message "Syntax error in date in query" expression". I have tried several different ways of writing the SQL String and I am at a loss. Any ideas? Am i even close to doing what I want?
On an Access form:
1. User selects a start weekending date from a combobox
2. User Selects an end weekending date from a combobox.
3. User clicks a button to start the process.
The process runs a query in Access with the dates the user selected and overwrites data in an existing Excel file.
Below is my code. I am getting a runtime error "3075" and the message "Syntax error in date in query" expression". I have tried several different ways of writing the SQL String and I am at a loss. Any ideas? Am i even close to doing what I want?
Code:
Private Sub CmdRunReport_Click()
Dim dbs As DAO.Database
Dim qdfTemp As DAO.QueryDef
Dim strSQL As String, strQDF As String
Set dbs = CurrentDb
' Selects the data in the query
strSQL = "SELECT * FROM ActualsWeeklyQuery " & _
"WHERE ActualsWeeklyQuery.WeekendingDate Between #" & ComboWeekendingDateStart & "#" & " And #" & ComboWeekendingDateEnd & "#;"
strQDF = "_TempQuery_"
Set qdfTemp = dbs.CreateQueryDef(strQDF, strSQL)
qdfTemp.Close
Set qdfTemp = Nothing
' Exports data to Excel file
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
strQDF, "C:\ExcelTest.xls"
dbs.QueryDefs.Delete strQDF
dbs.Close
Set dbs = Nothing
End Sub