ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Import Query from Access - Bug (https://www.excelbanter.com/excel-programming/392743-import-query-access-bug.html)

J@Y

Import Query from Access - Bug
 
I have this code:

Dim Data1 As ADODB.Recordset
Dim Connect As String

Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\db1.mdb;"

Set Data1 = New ADODB.Recordset
Data1.Open "[Test Q]", Connect

Sheets(1).Range("A1").CopyFromRecordset Data1

The Query "Test Q" works in Access and I get an output there. But when I run
it in here, nothing is copied over. The script works if I put a table in
there. Why is this happening?

Mike

Import Query from Access - Bug
 
Try this instead "Test Q"

"J@Y" wrote:

I have this code:

Dim Data1 As ADODB.Recordset
Dim Connect As String

Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\db1.mdb;"

Set Data1 = New ADODB.Recordset
Data1.Open "[Test Q]", Connect

Sheets(1).Range("A1").CopyFromRecordset Data1

The Query "Test Q" works in Access and I get an output there. But when I run
it in here, nothing is copied over. The script works if I put a table in
there. Why is this happening?


Mike

Import Query from Access - Bug
 


"J@Y" wrote:

I have this code:

Dim Data1 As ADODB.Recordset
Dim Connect As String

Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\db1.mdb;"

Set Data1 = New ADODB.Recordset
Data1.Open "[Test Q]", Connect

Sheets(1).Range("A1").CopyFromRecordset Data1

The Query "Test Q" works in Access and I get an output there. But when I run
it in here, nothing is copied over. The script works if I put a table in
there. Why is this happening?


J@Y

Import Query from Access - Bug
 
My code for Test Q:

SELECT *
FROM VTABLE
WHERE VTABLE.ID between (Select VTABLE.ID
FROM VTABLE
Where VTABLE.Account = "2")
AND
(Select MIN( VTABLE.ID)
From VTABLE
WHERE VTABLE.Name like "*000000000*" AND VTABLE.ID ( Select VTABLE.ID
FROM VTABLE
Where VTABLE.Account = "2"));


I think something doesn't work for excel here, I tried breaking apart this
into parts and each part worked.....


"Mike" wrote:

Try this instead "Test Q"

"J@Y" wrote:

I have this code:

Dim Data1 As ADODB.Recordset
Dim Connect As String

Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\db1.mdb;"

Set Data1 = New ADODB.Recordset
Data1.Open "[Test Q]", Connect

Sheets(1).Range("A1").CopyFromRecordset Data1

The Query "Test Q" works in Access and I get an output there. But when I run
it in here, nothing is copied over. The script works if I put a table in
there. Why is this happening?


J@Y

Import Query from Access - Bug
 
After alot of testing, the problem was Excel VB doesn't recognize Like
"*0000000*".
Instead of *, Excel uses %. This makes the Query not work in Access, but
works in Excel.

"J@Y" wrote:

My code for Test Q:

SELECT *
FROM VTABLE
WHERE VTABLE.ID between (Select VTABLE.ID
FROM VTABLE
Where VTABLE.Account = "2")
AND
(Select MIN( VTABLE.ID)
From VTABLE
WHERE VTABLE.Name like "*000000000*" AND VTABLE.ID ( Select VTABLE.ID
FROM VTABLE
Where VTABLE.Account = "2"));


I think something doesn't work for excel here, I tried breaking apart this
into parts and each part worked.....


"Mike" wrote:

Try this instead "Test Q"

"J@Y" wrote:

I have this code:

Dim Data1 As ADODB.Recordset
Dim Connect As String

Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\db1.mdb;"

Set Data1 = New ADODB.Recordset
Data1.Open "[Test Q]", Connect

Sheets(1).Range("A1").CopyFromRecordset Data1

The Query "Test Q" works in Access and I get an output there. But when I run
it in here, nothing is copied over. The script works if I put a table in
there. Why is this happening?



All times are GMT +1. The time now is 07:18 PM.

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