coconutt
asked on
runtime error 3061 too few parameters expected one
I am trying to execute this code:
Function FixLabels()
If Not IsNull(DLookup("PatientID" , "Qry_OverdueAppointments") ) Then
Dim dbs As Database
Dim rs As Recordset
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("Qry_Ove rdueAppoin tments")
MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
rs.Close
dbs.Close
Set rs = Nothing
Set dbs = Nothing
Forms!Form6!OverdueLab.Fon tBold = True
Forms!Form6!OverdueLab.For eColor = 195
Else
Forms!Form6!OverdueLab.Fon tBold = False
Forms!Form6!OverdueLab.For eColor = 0
End If
End Function
I get the dreaded error. 3061
Any thoughts?
Scott
Function FixLabels()
If Not IsNull(DLookup("PatientID"
Dim dbs As Database
Dim rs As Recordset
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("Qry_Ove
MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
rs.Close
dbs.Close
Set rs = Nothing
Set dbs = Nothing
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
Else
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
End If
End Function
I get the dreaded error. 3061
Any thoughts?
Scott
It looks like you're simply not supplying the required parameters to your Qry_OverdueAppointments query - can you post the SQL for this query?
FWIW, most developers will force newly created recordsets to the last record to get an accurate record count, so try something like this:
Function FixLabels()
If Not IsNull(DLookup("PatientID" , "Qry_OverdueAppointments") ) Then
Dim dbs As Database
Dim rs As Recordset
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("Qry_Ove rdueAppoin tments")
rs.movelast
rs.MoveFirst
MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
rs.Close
dbs.Close
Set rs = Nothing
Set dbs = Nothing
Forms!Form6!OverdueLab.Fon tBold = True
Forms!Form6!OverdueLab.For eColor = 195
Else
Forms!Form6!OverdueLab.Fon tBold = False
Forms!Form6!OverdueLab.For eColor = 0
End If
End Function
Also the "To few parameters" error typically indicates that the query needs a parameter and you did not supply the parameter at the time the recordset was created.
So look into this as well.
JeffCoachman
Function FixLabels()
If Not IsNull(DLookup("PatientID"
Dim dbs As Database
Dim rs As Recordset
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("Qry_Ove
rs.movelast
rs.MoveFirst
MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
rs.Close
dbs.Close
Set rs = Nothing
Set dbs = Nothing
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
Else
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
End If
End Function
Also the "To few parameters" error typically indicates that the query needs a parameter and you did not supply the parameter at the time the recordset was created.
So look into this as well.
JeffCoachman
ASKER
The parameter comes from a list box on my form, here is the sql behind Qry_OverdueAppointments
SELECT Appointments.AppointmentID , Count(Appointments.Appoint mentDate) AS CountOfAppointmentDate, Appointments.AppointmentKe pt, patients.PatientID, patients.FirstName, patients.LastName, [FirstName] & " " & [LastName] AS PatientName
FROM patients INNER JOIN Appointments ON patients.PatientID = Appointments.PatientID
GROUP BY Appointments.AppointmentID , Appointments.AppointmentKe pt, patients.PatientID, patients.FirstName, patients.LastName, [FirstName] & " " & [LastName]
HAVING (((Count(Appointments.Appo intmentDat e))<Date() ) AND ((Appointments.Appointment Kept)=No) AND ((patients.PatientID)=[For ms]![Form6 ]![Patient Id]));
SELECT Appointments.AppointmentID
FROM patients INNER JOIN Appointments ON patients.PatientID = Appointments.PatientID
GROUP BY Appointments.AppointmentID
HAVING (((Count(Appointments.Appo
Well, ...is this form open and is a value entered into the PatientId control, at the time the recordset is being created?
ASKER
The form is open, and the patient record is visible.
Is the form really called Form6?
JimD.
ASKER
yes the form is really called form6 ( I always meant to rename)
What type of a field is Appointments.AppointmentKe pt? In the query you are having it = No. If that is a text field, there needs to be quotes. If it is a Boolean field, try change it to FALSE
ASKER
tried that, nothing new. Look at image please
objvar.bmp
objvar.bmp
In Your SQL, Try changing:
AND ((patients.PatientID)=[For ms]![Form6 ]![Patient Id]));
To
AND ((patients.PatientID)=EVAL("[Forms]![Form6]![Pat ientId]") ));
mx
AND ((patients.PatientID)=[For
To
AND ((patients.PatientID)=EVAL("[Forms]![Form6]![Pat
mx
Change the code to the following:
Function FixLabels()
Dim dbs As Database
Dim rs As Recordset
Dim qdef As QueryDef
Dim prm as Parameter
If Not IsNull(DLookup("PatientID" , "Qry_OverdueAppointments") ) Then
Set dbs = CurrentDb
Set qdef = db.QueryDefs("Qry_OverdueA ppointment s")
For Each prm in qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdef.OpenRecordset()
MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
rs.Close
Set prm = Nothing
Set qdf = Nothing
Set rs = Nothing
Set dbs = Nothing
Forms!Form6!OverdueLab.Fon tBold = True
Forms!Form6!OverdueLab.For eColor = 195
Else
Forms!Form6!OverdueLab.Fon tBold = False
Forms!Form6!OverdueLab.For eColor = 0
End If
End Function
Function FixLabels()
Dim dbs As Database
Dim rs As Recordset
Dim qdef As QueryDef
Dim prm as Parameter
If Not IsNull(DLookup("PatientID"
Set dbs = CurrentDb
Set qdef = db.QueryDefs("Qry_OverdueA
For Each prm in qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdef.OpenRecordset()
MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
rs.Close
Set prm = Nothing
Set qdf = Nothing
Set rs = Nothing
Set dbs = Nothing
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
Else
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
End If
End Function
Also, all that code can be simplified to:
Function FixLabels()
If Not IsNull(DLookup("PatientID" , "Qry_OverdueAppointments") ) Then
With .OpenRecordset("Qry_Overdu eAppointme nts")
.MoveLast ' get record count
MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
End With
Forms!Form6!OverdueLab.Fon tBold = True
Forms!Form6!OverdueLab.For eColor = 195
Else
Forms!Form6!OverdueLab.Fon tBold = False
Forms!Form6!OverdueLab.For eColor = 0
End If
End Function
mx
Function FixLabels()
If Not IsNull(DLookup("PatientID"
With .OpenRecordset("Qry_Overdu
.MoveLast ' get record count
MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
End With
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
Else
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
End If
End Function
mx
and BTW, this:
MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
looks wrong. Think it should be:
MsgBox "The total for " & rs!PatientName & " is " & rs!CountofAppointmentDate
and why not just a DCount() or is it because of the patient name?
also for this, you don't need to return the first / last name as seperate fields, but rather simply:
SELECT Appointments.AppointmentID
FROM patients INNER JOIN Appointments ON patients.PatientID = Appointments.PatientID
GROUP BY Appointments.AppointmentID
HAVING (((Count(Appointments.Appo
JimD.
I need to correct my last post:
Function FixLabels()
If Not IsNull(DLookup("PatientID" , "Qry_OverdueAppointments") ) Then
With .OpenRecordset("Qry_Overdu eAppointme nts")
.MoveLast ' get record count
MsgBox "The total for " & ![PatientName] & " for the " & ![CountofAppointmentDate] & "is " & ![PatientID]
End With
Forms!Form6!OverdueLab.Fon tBold = True
Forms!Form6!OverdueLab.For eColor = 195
Else
Forms!Form6!OverdueLab.Fon tBold = False
Forms!Form6!OverdueLab.For eColor = 0
End If
End Function
Function FixLabels()
If Not IsNull(DLookup("PatientID"
With .OpenRecordset("Qry_Overdu
.MoveLast ' get record count
MsgBox "The total for " & ![PatientName] & " for the " & ![CountofAppointmentDate] & "is " & ![PatientID]
End With
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
Else
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
End If
End Function
ASKER
mx the last bit of code indicates in valid reference.
JDettman: yours worked, thank you. Yes I didnt ust dcount because of the patient name. But I really need to display the count of un-kept appointments.
JDettman: yours worked, thank you. Yes I didnt ust dcount because of the patient name. But I really need to display the count of un-kept appointments.
"mx the last bit of code indicates in valid reference. "
See my correct post just below that. It works ... I tested it.
mx
See my correct post just below that. It works ... I tested it.
mx
<<But I really need to display the count of un-kept appointments. >>
This is what you want then:
SELECT patients.PatientID, Last([FirstName] & " " & [LastName]) AS PatientName,
Count(Appointments.Appoint mentDate) AS CountOfAppointmentDate
FROM patients INNER JOIN Appointments ON patients.PatientID = Appointments.PatientID
WHERE Appointments.AppointmentDa te<Date() AND Appointments.AppointmentKe pt=No AND patients.PatientID =[Forms]![Form6]![PatientI d]
GROUP BY patients.PatientID;
and
Function FixLabels()
Dim dbs As Database
Dim rs As Recordset
Dim qdef As QueryDef
Dim prm as Parameter
If Not IsNull(DLookup("PatientID" , "Qry_OverdueAppointments") ) Then
Set dbs = CurrentDb
Set qdef = db.QueryDefs("Qry_OverdueA ppointment s")
For Each prm in qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdef.OpenRecordset()
MsgBox "The total for " & rs!PatientName & " is " & rs!CountofAppointmentDate
rs.Close
Set prm = Nothing
Set qdf = Nothing
Set rs = Nothing
Set dbs = Nothing
Forms!Form6!OverdueLab.Fon tBold = True
Forms!Form6!OverdueLab.For eColor = 195
Else
Forms!Form6!OverdueLab.Fon tBold = False
Forms!Form6!OverdueLab.For eColor = 0
End If
End Function
This is what you want then:
SELECT patients.PatientID, Last([FirstName] & " " & [LastName]) AS PatientName,
Count(Appointments.Appoint
FROM patients INNER JOIN Appointments ON patients.PatientID = Appointments.PatientID
WHERE Appointments.AppointmentDa
GROUP BY patients.PatientID;
and
Function FixLabels()
Dim dbs As Database
Dim rs As Recordset
Dim qdef As QueryDef
Dim prm as Parameter
If Not IsNull(DLookup("PatientID"
Set dbs = CurrentDb
Set qdef = db.QueryDefs("Qry_OverdueA
For Each prm in qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdef.OpenRecordset()
MsgBox "The total for " & rs!PatientName & " is " & rs!CountofAppointmentDate
rs.Close
Set prm = Nothing
Set qdf = Nothing
Set rs = Nothing
Set dbs = Nothing
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
Else
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
End If
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well ... one-more-time:
Function FixLabels()
If Not IsNull(DLookup("PatientID" , "Qry_OverdueAppointments") ) Then
With CurrentDB.OpenRecordset("Qry_Overdu eAppointme nts")
.MoveLast ' get record count
MsgBox "The total for " & ![PatientName] & " for the " & ![CountofAppointmentDate] & "is " & ![PatientID]
End With
Forms!Form6!OverdueLab.Fon tBold = True
Forms!Form6!OverdueLab.For eColor = 195
Else
Forms!Form6!OverdueLab.Fon tBold = False
Forms!Form6!OverdueLab.For eColor = 0
End If
End Function
Function FixLabels()
If Not IsNull(DLookup("PatientID"
With CurrentDB.OpenRecordset("Qry_Overdu
.MoveLast ' get record count
MsgBox "The total for " & ![PatientName] & " for the " & ![CountofAppointmentDate] & "is " & ![PatientID]
End With
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
Else
Forms!Form6!OverdueLab.Fon
Forms!Form6!OverdueLab.For
End If
End Function