I'm fairly new to Access VBA coding, and having a problem creating a recordset. I have the following code in an Access 2000 application:
Dim rstResources As Recordset
Dim strSQL2 As String
strSQL2 = "SELECT EventID, " _
& "[quantity reserved], ReservationStartDate, " _
& "ReservationStartTime, ReservationEndDate, " _
& "ReservationEndTime FROM EventResourcesDetails " _
& "WHERE ResourceID = " & cboResourceName _
& " AND (#" & txtStartDate _
& "# BETWEEN ReservationStartDate and ReservationEndDate OR #" _
& txtEndDate _
& "# BETWEEN ReservationStartDate and ReservationEndDate);"
Set rstResources = CurrentDb().OpenRecordset(strSQL2)
------------------------------------------------
When I run this code as is, I get a "type mismatch" error on the last statement. I tried adding double quotes, changing it to:
Set rstResources = CurrentDb().OpenRecordset("strSQL2"
and then get the following error instead of "type mismatch":
"The Microsoft Jet database engine cannot find the input table or query 'strSQL2'. Make sure it exists and that its name is spelled correctly."
I displayed the strSQL2 string, and it looks okay. Can anyone help me? Thanks in advance...
- Anita
Dim rstResources As Recordset
Dim strSQL2 As String
strSQL2 = "SELECT EventID, " _
& "[quantity reserved], ReservationStartDate, " _
& "ReservationStartTime, ReservationEndDate, " _
& "ReservationEndTime FROM EventResourcesDetails " _
& "WHERE ResourceID = " & cboResourceName _
& " AND (#" & txtStartDate _
& "# BETWEEN ReservationStartDate and ReservationEndDate OR #" _
& txtEndDate _
& "# BETWEEN ReservationStartDate and ReservationEndDate);"
Set rstResources = CurrentDb().OpenRecordset(strSQL2)
------------------------------------------------
When I run this code as is, I get a "type mismatch" error on the last statement. I tried adding double quotes, changing it to:
Set rstResources = CurrentDb().OpenRecordset("strSQL2"
and then get the following error instead of "type mismatch":
"The Microsoft Jet database engine cannot find the input table or query 'strSQL2'. Make sure it exists and that its name is spelled correctly."
I displayed the strSQL2 string, and it looks okay. Can anyone help me? Thanks in advance...
- Anita