SQL statement error

shery1995

Member
Local time
Today, 21:03
Joined
May 29, 2010
Messages
71
Hi All

I am trying to execute the following SELECT statement on my form but getting error:

sql = "SELECT DoctorsID,AppointDate,AppointTime FROM qrySubformAppoints WHERE DoctorsID=" & Me.ID & _
"AND AppointDate=#" & Me.txtAppointDate & "#;"

I would be grateful if can help.

Many thanks
 
Code:
sql = "SELECT DoctorsID,AppointDate,AppointTime FROM qrySubformAppoints WHERE DoctorsID=" & Me.ID & _
" AND AppointDate=#" & Me.txtAppointDate & "#;"
 
After assigning your SQL string use Debug.Print to view the output in the Immediate Window (Ctrl+G)
Code:
sql = "..."
Debug.Print sql
 
Code:
sql = "SELECT DoctorsID,AppointDate,AppointTime FROM qrySubformAppoints WHERE DoctorsID=" & Me.ID & _
" AND AppointDate=#" & Me.txtAppointDate & "#;"
Thank you for your reply. Still getting error message (Run-time error '3061': Too few parameters. Expected 1.
 
Then you have mis-spelt one of the field names or Me.txtAppointDate does not contain a valid date
 
See my post #4 and copy and paste the output from the Immediate Window here
 
See my post #4 and copy and paste the output from the Immediate Window here
SELECT DoctorsID,AppointDate,AppointTime FROM qrySubformAppoints WHERE DoctorsID=1 AND AppointDate=#14/09/2022#

many thanks in advance
 
What is the SQL of qrySubformAppoints?
SELECT tblApp.DoctorID, tblApp.ClientID, tblApp.AppointTime, tblApp.AppointDate, tblClients.ClientName
FROM tblSchedule INNER JOIN (tblClients INNER JOIN tblApp ON tblClients.ClientID = tblApp.ClientID) ON tblSchedule.DoctorsID = tblApp.DoctorID;
 
In SQL dates must be jn mm/dd/yyyy or yyyy-mm-dd format.
9/14/2022 NOT 14/09/2022
 
9/14/2022 NOT 14/09/2022
Whilst generally true, it shouldn't make a difference in this specific instance since the date, although in UK format, is not ambiguous.

The problem is that you are selecting DoctorsID instead of DoctorID, and again the WHERE clause.
 
Try it like:
Code:
sql = "SELECT DoctorID, AppointDate, AppointTime " & _
      "FROM qrySubformAppoints " & _
      "WHERE DoctorID = " & Me.ID & _
      "  AND AppointDate = " & Format(Me.txtAppointDate, "\#yyyy\-mm\-dd\#") & ";"
 
Try it like:
Code:
sql = "SELECT DoctorID, AppointDate, AppointTime " & _
      "FROM qrySubformAppoints " & _
      "WHERE DoctorID = " & Me.ID & _
      "  AND AppointDate = " & Format(Me.txtAppointDate, "\#yyyy\-mm\-dd\#") & ";"
Thank you very much for your help and advice. Fall sick and could not check the message.
 

Users who are viewing this thread

Back
Top Bottom