OpenRecordset Error

O

Orlando

Hi, I am trying to run this code and I get an error in this line of the code.

Set rs = db.OpenRecordset(vSql, dbOpenDynaset)

The error is:

Run-Time error '3061'
Too few parameters. expected 1

I just want to type the employee ID and display the name of the employee en
another box, I will display some more information as soon this code works, I
have check a lot of examples of OpenRecordset in this discussion group but I
haven't find the mistake.

I would really appreciate if someone can help me.

Thanks

Private Sub Command7_Click()
Dim vSql As String
Dim db As Database, rs As Recordset

vSql = ""
vSql = "Select employees.EmpID, employees.FirstName " _
& "from employees where Employees.EmpID = " & Me.EmpID
Set db = CurrentDb
Set rs = db.OpenRecordset(vSql, dbOpenDynaset)
If rs.RecordCount > 0 Then
Me.FirstName.Value = rs!FirstName
Else
Me.FirstName.Value = "ERROR - el depto que ingreso no existe, verifique"
Me.EmpID.SetFocus
Exit Sub
End If
rs.Close
Set db = Nothing
End Sub
 
R

Rick Brandt

Orlando said:
Hi, I am trying to run this code and I get an error in this line of
the code.

Set rs = db.OpenRecordset(vSql, dbOpenDynaset)

The error is:

Run-Time error '3061'
Too few parameters. expected 1

I just want to type the employee ID and display the name of the
employee en another box, I will display some more information as soon
this code works, I have check a lot of examples of OpenRecordset in
this discussion group but I haven't find the mistake.

I would really appreciate if someone can help me.

Thanks

Private Sub Command7_Click()
Dim vSql As String
Dim db As Database, rs As Recordset

vSql = ""
vSql = "Select employees.EmpID, employees.FirstName " _
& "from employees where Employees.EmpID = " & Me.EmpID
Set db = CurrentDb
Set rs = db.OpenRecordset(vSql, dbOpenDynaset)
If rs.RecordCount > 0 Then
Me.FirstName.Value = rs!FirstName
Else
Me.FirstName.Value = "ERROR - el depto que ingreso no existe,
verifique" Me.EmpID.SetFocus
Exit Sub
End If
rs.Close
Set db = Nothing
End Sub

Are you quite sure of the spelling of the field names? That is a common cause
of that error.
 
O

Orlando

Yes, I just check all the files and table name and are right, do you know
what i this error 3061 about?
 
O

Orlando

Employees is a table, yes an sure the openrecordset statement isn't the
problem is in the select or something related to the table, EmpID in the
table is text, is that a problem?
 
R

Rick Brandt

Orlando said:
Employees is a table, yes an sure the openrecordset statement isn't
the problem is in the select or something related to the table, EmpID
in the table is text, is that a problem?

Yep, It means you have to put quotes around the value...

vSql = "Select employees.EmpID, employees.FirstName " _
& "from employees where Employees.EmpID = '" & Me.EmpID & "'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top