ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   DAO Recordset in Excel (https://www.excelbanter.com/excel-programming/312242-dao-recordset-excel.html)

Andy

DAO Recordset in Excel
 
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.


Chip Pearson

DAO Recordset in Excel
 
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




"Andy" wrote in message
...
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.




Andy

DAO Recordset in Excel
 
Great - thanks - worked OK.

"Andy" wrote:

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.



All times are GMT +1. The time now is 03:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com