Solved

Error 3061: Too Few Parameters. Expected 2

Posted on 2004-08-23
12
268 Views
Last Modified: 2013-12-25
Hi all,

I am struggling with this error.

I have some simple test code and it works fine:

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String
    Dim SpectrumID As String
    Dim idLoadGroup As String
   
    Set db = OpenDatabase("D:\Dev\CIRCLY50 and APSDS50 Common Files\data\aaa For database design etc\loads.mdb")   ' Open database.
   
    SpectrumID = "2000"
    idLoadGroup = "Kalm37012"
   
    strSQL = "Select * from TrafficMixComponents Where ((TrafficSpectrumID='" & SpectrumID & "') And (idLoadGroup='" & idLoadGroup & "')) ORDER BY sglTrafficMixLoadGroupLoadMin"
   
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    MsgBox rs.RecordCount

But when I use the same code on the same database in a more sophisticated application, I get the error.
So I believe the syntax of the SQL query is OK.
Could it be something more subtle?

Regards,
Leigh
0
Comment
Question by:LeighWardle
  • 5
  • 5
  • 2
12 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 11877547
that error occurs if you dont have the right " " around strings and # # around date/times

In the above, it looks like both your ID's are text fields.  is this right??

If you post the strSQL of the ones that dont work, with the table data types for the fields,  can fix them up...

Dave
0
 
LVL 34

Expert Comment

by:flavo
ID: 11877551
sorry

>> In the above, it looks like both your ID's are text fields.

In the above, it looks like both your fields are text fields.

Dave
0
 
LVL 1

Author Comment

by:LeighWardle
ID: 11877651
Thanks, Dave, for your response.

Yes, both fields are text fields.

Leigh
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:LeighWardle
ID: 11877661
Here is a sample of the SQL query that gives the error:

Select * from TrafficMixComponents Where ((TrafficSpectrumID='2000') And (idLoadGroup='HysterH40C')) ORDER BY sglTrafficMixLoadGroupLoadMin

Leigh
0
 
LVL 34

Accepted Solution

by:
flavo earned 200 total points
ID: 11877691
It looks fine

Try copy and paste it into the query builder and see if that works

Dave
0
 
LVL 1

Author Comment

by:LeighWardle
ID: 11877756
I am using Access 1.1 format databases, so couldn't use query builder.
But it works fine in Access 1.1 SQL window.

Leigh
0
 
LVL 34

Expert Comment

by:flavo
ID: 11877787
1.1 geezz.... i cant even remember it

not sure then... in DAO 3.6 w/ Access 97 its sweet.
0
 
LVL 1

Author Comment

by:LeighWardle
ID: 11877857
As a test, I created a sub that consists of the code posted above.

I call the sub immediately before the code that gives the error, and the sub works fine.  But then my  next statement, i.e.

       Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)

bombs with the error.
So that's why I think it is something more subtle than just the SQL syntax.
0
 
LVL 29

Assisted Solution

by:leonstryker
leonstryker earned 50 total points
ID: 11880985
Try very simple syntax and see if that works:

Select * from TrafficMixComponents

If this works then you have a syntax problem, if it doesn't then it is something else.

Leon
0
 
LVL 1

Author Comment

by:LeighWardle
ID: 11889834
Hi all,

My problem has been solved, the error was due to me using a database that had an out-of-date version of my table.  It didn't have all the fields that were referenced in the SQL query.

Everything worked OK when I used the correct version of my database and table.

Thanks for your help.
I don't know how to allocate the points.

Regards,

Leigh
0
 
LVL 34

Expert Comment

by:flavo
ID: 11889842
Leigh,

Glad its all working for you now..

>>I  don't know how to allocate the points.
not too fussed..

Dave :-)

0
 
LVL 29

Expert Comment

by:leonstryker
ID: 11891490
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 228
VB6 - Compare and highlight cell not the same 3 54
VB6 ListBox Question 4 50
Send outlook email from VBS Script 2 46
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question