I'm using a simple SQL query to return a RecordSet WHERE a field labeled DoctorID equals a string variable AND the ApptDateTime field equals a variable holding a Date. The query works when I omit the second WHERE clause (it only matches the DoctorID), so I know the error is either how I'm setting up my query with 2 WHERE clauses compounded, or how I'm referring to the date. The date passed to the variable matches the date in my database exactly though.

Here's the code in my function:

VB Code:
  1. Private Function DuplicateAppt(DocID As String, DateTime As Date) As Boolean
  2.     Dim strSQL As String
  3.     strSQL = "SELECT * FROM Appointments WHERE DoctorID ='" _
  4.         & DocID & "' AND ApptDateTime = %" & DateTime & "%;"
  5.     Call rsAppointments.Open(strSQL, cnSchedule, adOpenStatic, adCmdText)
  6.     DuplicateAppt = Not (rsAppointments.EOF)
  7.     rsAppointments.Close
  8.    
  9. End Function

The value I'm passing to the DateTime argument works like this:

VB Code:
  1. dtpDate.Value + TimeValue(dtpTime.Value)

and it looks fine when I debug to check the value that gets passed.

The error message I get when I run it is:

Run-time error '-2147217900 (80040e14)
Syntax error in query expression 'DoctorID = '1005' AND ApptDateTime = %11/27/2002 9:00:00 AM%'.

Am I passing the date wrong? Am I doing my multiple WHERE clauses wrong? I've played around with both and still get similar error message every time.

Thanks!