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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using SQL Statement in VBA

Status
Not open for further replies.

rvermin

MIS
Jan 1, 2003
7
BE
I have a code that looks like this:

Dim db As Database
Dim rs As Recordset
Dim StrsQL As String
Dim SvAr As String

Set db = CurrentDb

SvAr ="A" 'not really "A", actually a value from control, but for ease of explanation I use "A"

StrsQL = "SELECT * From [Table1] Where ([Category] = (SvAr))"

Set rs = db.OpenRecordset(StrsQL, dbOpenSnapshot)


.... some mor e code follows.

Now, why isn't this SqL statement working?

It gives the error message "RunTime error 3061, too few Parameters. Expected 1."

Please help.

Ramon



 
Ramon,

I think that Access is getting confused between the DAO and ADO libraries. Firstly, go to Tools -> REferences and make sure there is a tick in the box next to "Microsoft DAO 3.6 Object Library" and then change your code to read:

Dim db As DAO.Database
Dim rs As DAO.Recordset

This should be enough to fix your problem.

John
 
Your code should be:

StrsQL = "SELECT * From [Table1] Where ([Category] = " & A & ")"

If it's a text string then it should read

StrsQL = "SELECT * From [Table1] Where ([Category] = '" & A & "')"

 
Many thanks Both of You!!!
It Works! 3.6 wasn't registered and " " + the ' worked!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top