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!

Error #3061 When Using OpenRecordset Method. 1

Status
Not open for further replies.

Weltman

Programmer
Apr 27, 2001
17
US
I have a sub beginning with the following code:
Public Sub PreviousCat()
On Error GoTo EditCatError
Dim I As Integer
Dim MyDB As Database, MyRs As Recordset, FilteredSet As Recordset, CatQuery As String
10 Set MyDB = DBEngine.Workspaces(0).OpenDatabase("C:\Program Files\Microsoft Visual Basic\Ballots\BALLOTS.mdb")
20 Set MyRs = MyDB.OpenRecordset("Names", dbOpenDynaset)
30 If MyRs.RecordCount > 0 Then
40 MyRs.MoveFirst
45 txtCatID.Text = MyRs![CatID] 'ID number of first category.
55 VarBallotPage = MyRs![BallotPage] 'Page number of first category
60 CatQuery = "SELECT * FROM Names WHERE BallotNumber = VarBallotNumber AND BallotPage = VarBallotPage AND CatID = VarCategoryID"
'Create a Dynaset based on the parameter query
70 Set FilteredSet = MyDB.OpenRecordset(CatQuery, dbOpenDynaset)

When I try to run it, I'm getting Error #3061. Too few parameters. Expected 3. on line #70.
Can anybody tell me why and what I can do about it? Thanks.

Weltman
 
It looks like line 60 should read:
CatQuery = "SELECT * FROM Names WHERE BallotNumber = " & VarBallotNumber & " AND BallotPage = " & VarBallotPage & " AND CatID = " & VarCategoryID

I'm assuming that BallotNumber, BallotPage, and CatID are all numeric. If they are not, then you'll have to quote the variables. (ie: ... AND BallotPage = '" & varBallotPage & "' AND ....)
 
This error usually comes coz we're select an unexisted field from table. Check your SQL statement. BeerFreak has point too.
 
BeerFreak,
Thanks. The query works now, with syntax errors removed. Also, OpenRecordset likes it. Although, I don't thoroughly understand it, here is the final statement:
60 CatQuery = "SELECT * FROM Names " & " WHERE BallotNumber = '" & VarBallotNumber & "' AND BallotPage = '" & VarBallotPage & "' AND CatID = " & VarCategoryID & ""
Weltman
 
BeerFreak will you marry me. This little piece of code fixed my PROJECT and saved my marriage and yadda yadda yadda.


thanks

joseguia
janitor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top