Stumped by a Type mismatch error

L

Len B

Relevant VBA snippets -

DIM dbsTadPJ as Database, rstPJ as Recordset, stSQLExport as String
stSQLExport = "SELECT SupplierInvoice ....
stSQLExport = stSQLExport & "FROM Purchases INNER JOIN ...
stSQLExport = stSQLExport & "GROUP BY ...

Set dbsTadPJ = CurrentDb()
Set rstPJ = dbsTadPJ.OpenRecordset(stSQLExport, dbOpenDynaset) ****

Line **** generates Type mismatch error. I have used this syntax
successfully elsewhere.

By using a breakpoint and the intermediate window, I got the SQL string
produced by the concatenation process into the clipboard. I then pasted
it into a new query which produced the 13 records I was expecting.

As far as I can see I am attempting to assign a recordset to a variable
of type recordset. Aren't I? Any hints what to try now.
 
G

Gigamite

Len said:
DIM dbsTadPJ as Database, rstPJ as Recordset, stSQLExport as String

You've referenced 2 libraries with the same object name, so you have to
tell Access which library your code is using. It defaults to the first
one on the list. In your case, that's the ADODB library, which you
aren't using in this procedure. Change:

Dim rstPJ as Recordset

to:

Dim rstPJ as DAO.Recordset
 
L

Len B

That did the trick. Thanks.

--
Len
______________________________________________________
remove nothing for valid email address.
| Len B wrote:
|
| > DIM dbsTadPJ as Database, rstPJ as Recordset, stSQLExport as String
|
| You've referenced 2 libraries with the same object name, so you have to
| tell Access which library your code is using. It defaults to the first
| one on the list. In your case, that's the ADODB library, which you
| aren't using in this procedure. Change:
|
| Dim rstPJ as Recordset
|
| to:
|
| Dim rstPJ as DAO.Recordset
 

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