Exporting certain Access data to Excel in VBA using specific Range data

needhelpwithvba

New Member
Joined
Aug 5, 2011
Messages
4
Hi,

I'm trying to export specific rows from Access to Excel given a particular parameter defined in cell D32 of my Excel sheet (in this case the value for Dogs must be equal to what is in cell D32). Below is the portion of code that is not working:

Const strDb As String = "C:\Pets.mdb"
Const strQry As String = "SELECT * from [Canines] WHERE ([Canines].[Dogs]=Range("D32").Value)"

Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Ace.OLEDB.12.0; Persist Security Info = False; " & "Data Source=C:\Pets.mdb;"
Set rs = New ADODB.Recordset


The code is specifically not happy with 'Range("D32").Value'. I've tried replacing that part of code with the number 3 and it works fine in that case. Any help would be greatly appreciated!!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top