Solved

runtime error 3061 too few parameters expected one

Posted on 2011-03-09
20
500 Views
Last Modified: 2013-11-27
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_OverdueAppointments")
        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.FontBold = True
        Forms!Form6!OverdueLab.ForeColor = 195
   Else
        Forms!Form6!OverdueLab.FontBold = False
        Forms!Form6!OverdueLab.ForeColor = 0
    End If
End Function

I get the dreaded error. 3061

Any thoughts?
Scott
0
Comment
Question by:coconutt
  • 6
  • 5
  • 5
  • +3
20 Comments
 
LVL 17

Expert Comment

by:JezWalters
ID: 35084058
It looks like you're simply not supplying the required parameters to your Qry_OverdueAppointments query - can you post the SQL for this query?
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35084066
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_OverdueAppointments")
        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.FontBold = True
        Forms!Form6!OverdueLab.ForeColor = 195
   Else
        Forms!Form6!OverdueLab.FontBold = False
        Forms!Form6!OverdueLab.ForeColor = 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
0
 

Author Comment

by:coconutt
ID: 35084369
The parameter comes from a list box on my form, here is the sql behind Qry_OverdueAppointments

SELECT Appointments.AppointmentID, Count(Appointments.AppointmentDate) AS CountOfAppointmentDate, Appointments.AppointmentKept, 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.AppointmentKept, patients.PatientID, patients.FirstName, patients.LastName, [FirstName] & " " & [LastName]
HAVING (((Count(Appointments.AppointmentDate))<Date()) AND ((Appointments.AppointmentKept)=No) AND ((patients.PatientID)=[Forms]![Form6]![PatientId]));
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35084810
Well,  ...is this form open and is a value entered into the PatientId control, at the time the recordset is being created?
0
 

Author Comment

by:coconutt
ID: 35084839
The form is open, and the patient record is visible.
0
 
LVL 57
ID: 35084982

 Is the form really called Form6?

JimD.
0
 

Author Comment

by:coconutt
ID: 35085048
yes the form is really called form6 ( I always meant to rename)
0
 
LVL 1

Expert Comment

by:kavik379
ID: 35085085
What type of a field is Appointments.AppointmentKept? 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
0
 

Author Comment

by:coconutt
ID: 35085136
tried that, nothing new. Look at image please
objvar.bmp
0
 
LVL 75
ID: 35085322
In Your SQL, Try changing:

AND ((patients.PatientID)=[Forms]![Form6]![PatientId]));

To

AND ((patients.PatientID)=EVAL("[Forms]![Form6]![PatientId]") ));

mx
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 57
ID: 35085377
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_OverdueAppointments")
        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.FontBold = True
        Forms!Form6!OverdueLab.ForeColor = 195
   Else
        Forms!Form6!OverdueLab.FontBold = False
        Forms!Form6!OverdueLab.ForeColor = 0
    End If

End Function


0
 
LVL 75
ID: 35085423
Also, all that code can be simplified to:

Function FixLabels()
    If Not IsNull(DLookup("PatientID", "Qry_OverdueAppointments")) Then
       With .OpenRecordset("Qry_OverdueAppointments")
             .MoveLast  ' get record count
        MsgBox "The total for " & rs!PatientName & " for the " & rs!CountofAppointmentDate & "is " & rs!PatientID
     End With

   
        Forms!Form6!OverdueLab.FontBold = True
        Forms!Form6!OverdueLab.ForeColor = 195
   Else
        Forms!Form6!OverdueLab.FontBold = False
        Forms!Form6!OverdueLab.ForeColor = 0
    End If
End Function

mx
0
 
LVL 57
ID: 35085453

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, Count(Appointments.AppointmentDate) AS CountOfAppointmentDate, Appointments.AppointmentKept, patients.PatientID, [FirstName] & " " & [LastName] AS PatientName
FROM patients INNER JOIN Appointments ON patients.PatientID = Appointments.PatientID
GROUP BY Appointments.AppointmentID, Appointments.AppointmentKept, patients.PatientID
HAVING (((Count(Appointments.AppointmentDate))<Date()) AND ((Appointments.AppointmentKept)=No) AND ((patients.PatientID)=[Forms]![Form6]![PatientId]));

JimD.
0
 
LVL 75
ID: 35085502
I need to correct my last post:



Function FixLabels()
    If Not IsNull(DLookup("PatientID", "Qry_OverdueAppointments")) Then
       With .OpenRecordset("Qry_OverdueAppointments")
             .MoveLast  ' get record count
       MsgBox "The total for " & ![PatientName] & " for the " & ![CountofAppointmentDate] & "is " & ![PatientID]
     End With
   
        Forms!Form6!OverdueLab.FontBold = True
        Forms!Form6!OverdueLab.ForeColor = 195
   Else
        Forms!Form6!OverdueLab.FontBold = False
        Forms!Form6!OverdueLab.ForeColor = 0
    End If
End Function
0
 

Author Comment

by:coconutt
ID: 35085581
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.
0
 
LVL 75
ID: 35085603
"mx the last bit of code indicates in valid reference. "
See my correct post just below that.  It works ... I tested it.

mx
0
 
LVL 75
ID: 35085616
And see http:#a35085322  using the Eval() function in your SQL.  That also works.

mx
0
 
LVL 57
ID: 35085765
<<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.AppointmentDate) AS CountOfAppointmentDate
FROM patients INNER JOIN Appointments ON patients.PatientID = Appointments.PatientID
WHERE Appointments.AppointmentDate<Date() AND Appointments.AppointmentKept=No AND patients.PatientID =[Forms]![Form6]![PatientId]
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_OverdueAppointments")
        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.FontBold = True
        Forms!Form6!OverdueLab.ForeColor = 195
   Else
        Forms!Form6!OverdueLab.FontBold = False
        Forms!Form6!OverdueLab.ForeColor = 0
    End If

End Function

0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 35085801

BTW, this would be better:

Function FixLabels()

  Dim dbs As Database
  Dim rs As Recordset
  Dim qdef As QueryDef
  Dim prm as Parameter

  Set dbs = CurrentDb
  Set qdef = db.QueryDefs("Qry_OverdueAppointments")
  For Each prm in qdf.Parameters
      prm.Value = Eval(prm.Name)
  Next prm
  Set rs =  qdef.OpenRecordset()  
  If rs.recordCount>0 then
        MsgBox "The total for " & rs!PatientName & " is " & rs!CountofAppointmentDate
 
        Forms!Form6!OverdueLab.FontBold = True
        Forms!Form6!OverdueLab.ForeColor = 195
   Else
        Forms!Form6!OverdueLab.FontBold = False
        Forms!Form6!OverdueLab.ForeColor = 0
    End If

    rs.Close
    Set prm = Nothing
    Set qdf = Nothing
    Set rs = Nothing
    Set dbs = Nothing

End Function

  Your not executing the query 2X that way.

JimD.
0
 
LVL 75
ID: 35085843
Well ... one-more-time:


Function FixLabels()
    If Not IsNull(DLookup("PatientID", "Qry_OverdueAppointments")) Then
       With CurrentDB.OpenRecordset("Qry_OverdueAppointments")
             .MoveLast  ' get record count
       MsgBox "The total for " & ![PatientName] & " for the " & ![CountofAppointmentDate] & "is " & ![PatientID]
     End With
   
        Forms!Form6!OverdueLab.FontBold = True
        Forms!Form6!OverdueLab.ForeColor = 195
   Else
        Forms!Form6!OverdueLab.FontBold = False
        Forms!Form6!OverdueLab.ForeColor = 0
    End If
End Function
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now