Error 3061 - Too few parameters - expected 1. (1 Viewer)

mikewood1980

Registered User.
Local time
Today, 15:32
Joined
May 14, 2008
Messages
45
Hi

When executing the following SQL statement in VBA...

Code:
Private Function createAdverseDeviationsString(strTestID As String) As String

        Dim dbcurr As Database
        Set dbcurr = DBEngine.Workspaces(0).Databases(0)
        
        Dim sQuery As String
        sQuery = "select * from tblAdverseDeviations where ((tblAdverseDeviations.chrTestID)=" & strTestID & ")"
        
        Dim rsADTable As Recordset
        Set rsADTable = dbcurr.OpenRecordset(sQuery)
        
        Dim testFound As Boolean
        Dim count As Integer
        count = 0

...etc
I get the following error...

Error 3061 - Too few parameters. Expected 1.

This occurs on the line:

Code:
 Set rsADTable = dbcurr.OpenRecordset(sQuery)

If anyone can help that would be great (I've not really used SQL statements that much before so I am a bit of a novice!)

Thanks in advance
Mike Wood
 

khawar

AWF VIP
Local time
Today, 18:32
Joined
Oct 28, 2006
Messages
870
sQuery = "select * from tblAdverseDeviations where ((tblAdverseDeviations.chrTestID)='" & strTestID & "')"
 

namliam

The Mailman - AWF VIP
Local time
Today, 16:32
Joined
Aug 11, 2003
Messages
11,695
FYI

Strings you have to enclose with ' and dates with #, numbers you dont need to enclose.
So i.e. if your strTestID is a string:
sQuery = "select * from tblAdverseDeviations where ((tblAdverseDeviations.chrTestID)='" & strTestID & "')" (What khawar said)
strTestID is a date:
sQuery = "select * from tblAdverseDeviations where ((tblAdverseDeviations.chrTestID)=#" & strTestID & "#)"
strTestID is a number:
sQuery = "select * from tblAdverseDeviations where ((tblAdverseDeviations.chrTestID)=" & strTestID & ")" (what you had...)

Happy coding :)
 

mikewood1980

Registered User.
Local time
Today, 15:32
Joined
May 14, 2008
Messages
45
Thanks guys - that really helped!
Mike
PS thanks for the tips Namliam!
 

Darth Vodka

Registered User.
Local time
Today, 15:32
Joined
Sep 25, 2007
Messages
344
you should use the debug window when the code debugs and type

?sQuery

then copy and paste this into query design and see if there's any faults in the SQL

you'll find yourself doing that ALL the time :D
 

Users who are viewing this thread

Top Bottom