OpenRecordset Error

G

Guest

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.
 
G

Guest

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

Rick Brandt

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

Well specifically, "too few parameters" means that the query engine thinks that
it see a parameter marker that has not been defined or not given a value. If
you spell a field name incorrectly it will look like a parameter marker which is
why I suggested you check that.

Is "employees" a table or query? If the latter the parameter marker could be in
that query rather than you SQL Statement.
 
G

Guest

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