Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / March 2007

Tip: Looking for answers? Try searching our database.

OpenRecordset Error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Orlando - 18 Mar 2007 01:35 GMT
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
Rick Brandt - 18 Mar 2007 01:40 GMT
> Hi, I am trying to run this code and I get an error in this line of
> the code.
[quoted text clipped - 34 lines]
> Set db = Nothing
> End Sub

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

Signature

Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt   at   Hunter   dot   com

Orlando - 18 Mar 2007 01:55 GMT
Yes, I just check all the files and table name and are right, do you know
what i this error 3061 about?

> > Hi, I am trying to run this code and I get an error in this line of
> > the code.
[quoted text clipped - 37 lines]
> Are you quite sure of the spelling of the field names?  That is a common cause
> of that error.
Rick Brandt - 18 Mar 2007 02:03 GMT
> 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.

Signature

Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt   at   Hunter   dot   com

Orlando - 18 Mar 2007 02:30 GMT
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?

> > Yes, I just check all the files and table name and are right, do you
> > know what i this error 3061 about?
[quoted text clipped - 6 lines]
> Is "employees" a table or query?  If the latter the parameter marker could be in
> that query rather than you SQL Statement.
Rick Brandt - 18 Mar 2007 02:38 GMT
> 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 & "'"

Signature

Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt   at   Hunter   dot   com

Orlando - 18 Mar 2007 04:16 GMT
Thanks Rick It works perfectly, like magic.

I appreciate your help.

> > 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
[quoted text clipped - 4 lines]
> vSql = "Select employees.EmpID, employees.FirstName " _
> & "from employees where Employees.EmpID = '" & Me.EmpID & "'"
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.