DAO Recordset in Excel

G

Guest

I'm trying to populate a recordset using a query in Excel VB code as below :-

Dim db As Database
Dim rs1 As Recordset
Dim SQLstr As String
Dim OrigCP As Variant

OrigCP = "AB123"

db = "c:\my.mdb"

SQLstr = "SELECT History.Field2, History.OrigCP FROM History WHERE
History.OrigCP=" & OrigCP
Set rs1 = db.OpenRecordset(SQLstr)

I get an error 3061 (Too few Parameters - Expected 1).

Any ideas? - I've done this lots directly in Access VB OK.

Thanks.
 
C

Chip Pearson

Andy,

Try
SQLstr = "SELECT History.Field2, History.OrigCP FROM History
WHERE " & _
History.OrigCP = "'" & OrigCP & "'"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top