Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime Error 3061

Status
Not open for further replies.

Rzrbkpk

Technical User
Mar 24, 2004
84
US
I'm missing something in this process. When I run the code below, I get a "Runtime Error 3061: Too Few Parameters. Expected 2". This module runs after users key in their ID and Password. The query "qryUserValidate" runs based on this form. Maybe I have to open this query???

Function logon()

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("qryUserValidate")

If rs.RecordCount > 0 Then
DoCmd.Minimize
DoCmd.OpenForm "Main Menu"
Else
MsgBox "User ID or Password not Valid", vbOKOnly, "Warning"
End If

rs.Close
Set db = Nothing

End Function
 
Put it in a Sub, not a function. Also, how are you passing in the name and password that the query is probably expecting? That is probably where the "expected 2" error is coming from.
 
I tried Sub, but no change. Sorry, I'm not sure that I understand what you mean by how am I passing in the name and password...need a little more detail.
 
Subs do work where Functions return values. Here is and example.
Code:
Private Sub Command0_Click()
Dim NameToPass As String
Dim PasswordToPass As String

NameToPass = InputBox("Please enter your login name", "Name Please")
PasswordToPass = InputBox("Please enter your password", "Password Please")
'Calls the sub and passes the name and password that gets placed in the select statement
Call DisplayResults(NameToPass, PasswordToPass)

End Sub

Private Sub DisplayResults(sName As String, sPassword As String)
On Error GoTo ErrHandler
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim a As Integer
Dim b As Integer

Set db = CurrentDb
'Set rs = db.OpenRecordset("qryGetPassword")
strSql = "SELECT Name, Password FROM tblPassword WHERE Name = '" & sName & _
"' AND Password = '" & sPassword & "'"
Set rs = db.OpenRecordset(strSql)

If rs.RecordCount > 0 Then
    'DoCmd.Minimize
    'DoCmd.OpenForm "frmMainForm"
    MsgBox "Password validated!", vbOKOnly, "Success"
Else
MsgBox "User ID or Password not Valid", vbOKOnly, "Failed"
End If

Set rs = Nothing
Set db = Nothing
'Shows you how a function works
a = InputBox("Please enter the first number to add", "Math Function")
b = InputBox("Please entere the second number to add", "Math Function")

MsgBox "I added the numbers and multiplied by 4, the reults = " & DoSomeMath(a, b), vbOKOnly, "Math complete"


Exit Sub
ErrHandler:
    MsgBox "Error getting password info. Error # " & Err.Number & ", " & Err.Description, vbOKOnly, "Error"
End Sub
Private Function DoSomeMath(iFirstNumber As Integer, iSecondNumber As Integer) As Integer

DoSomeMath = (iFirstNumber + iSecondNumber) * 4


End Function

If you alter the code to fit your table or create a table like I did with the same name and columns this will work. You can then step through the code to see how it works.
Note:
I don't have error trapping in the function so make sure you enter a number.
 
How are ya Rzrbkpk . . .

Post the [blue]SQL[/blue] of the query [blue]qryUserValidate[/blue] . . .

Calvin.gif
See Ya! . . . . . .
 
Chances are ... qryUserValidate is a parameter query (i.e. it has user-input parameters defined.) When you run it this way it doesn't generate input boxes for the parameters and then errors out because it doesn't have values for them. You may need something like
Code:
Dim qd As DAO.Querydef
Set qd = Currentdb.QueryDefs("qryUserValidate")
qd.Parameters("FirstParm") = "SomeValue"
qd.Parameters("SecondParm") = "SomeOtherValue"
Set rs = qd.OpenRecordset

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
D,
Thanks for the info, but I need the form that the Users input their logon information onto. I follow you on the input boxes, but I can't go that route.

Golom,
qryUserValidate is a parameter query that uses the criteria from a form titled "Log On". I need a little more help with the code you provided. I'm still new at this.

Here is the SQL from that query:

SELECT UserID.[User ID], UserID.Password
FROM UserID
WHERE (((UserID.[User ID])=[Forms]![Log On]![userid]) AND ((UserID.Password)=[Forms]![Log On]![password]))
WITH OWNERACCESS OPTION;

 
Rzrbkpk . . . Yes! Ideas abound! . . .

All depends on wether the form where users enter ID & Password is still open when you run your code! . . . Is this correct . . . or not?

My intent is to enter the parameters directly if the form is still open by modifying the SQL of [blue]qryUserValidate[/blue] and use that as recordsource for the recordset in . . .
Code:
[blue]Set rs = db.OpenRecordset("SQL, dbOpenDynaset)[/blue]
This is indicitive of my asking you to post the SQL of the query earlier on!

[blue]Your thoughts?[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top