|
-
Nov 27th, 2002, 01:43 PM
#1
Thread Starter
Member
SQL ? (WHERE clause and DATE format)
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:
Private Function DuplicateAppt(DocID As String, DateTime As Date) As Boolean
Dim strSQL As String
strSQL = "SELECT * FROM Appointments WHERE DoctorID ='" _
& DocID & "' AND ApptDateTime = %" & DateTime & "%;"
Call rsAppointments.Open(strSQL, cnSchedule, adOpenStatic, adCmdText)
DuplicateAppt = Not (rsAppointments.EOF)
rsAppointments.Close
End Function
The value I'm passing to the DateTime argument works like this:
VB Code:
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!
Rich Stern
http://www.AcidPlanet.com/Jasp182
http://www.InsomniacRecords.com
http://www.mp3.com/Jasp182
-
Nov 27th, 2002, 01:46 PM
#2
% is wrong should be either # or '. # in access, ' for SQL
-
Nov 27th, 2002, 02:01 PM
#3
Thread Starter
Member
Dude...I love this place!
I tried the ' symbol, but I didn't try the pound sign (#), and now it works like a charm.
Thanks a million!
Rich Stern
http://www.AcidPlanet.com/Jasp182
http://www.InsomniacRecords.com
http://www.mp3.com/Jasp182
-
Nov 27th, 2002, 02:06 PM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|