Pass Range Reference as query Parameter

turbovr6mang

New Member
Joined
Mar 27, 2009
Messages
3
A new statistic has been requested for a weekly report which will require pulling a query from an Access database. I'm attempting to mimic an existing VBA procedure that pulls a sum of emails sent based on a date variable (and some other criteria).

I simply want to pass some dates (stored on the margin of the report worksheet) as parameters for the query, but can't get the syntax right. At this point, I'm getting a debug error "Undefined function 'Range' in expression.

I'm a total noob to Access and pretty fragile with VBA so if you have any tips for getting up to speed with Excel/Access integration, it would be much appreciated.

Here's my code:
Sub_GetFunded()

'Set source
MyConn = "\\dir\file"


'Select Output Range
Sheets("Wkly_v2").Select
Range("Q2").Activate

'Get Records for Funded
sSQL = "SELECT Count(qryFunded.Acct) AS CountOfAcct " & _
"FROM qryCSRPT_Funded_Subquery " & _
"WHERE ((qryCSRPT_Funded_Subquery.created >= Range('S2')) And (qryCSRPT_Funded_Subquery.FundDate >= Range('S4')));"

'Create RecordSet for Emails Sent Query
Set Cn = New ADODB.Connection
With Cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open MyConn
Set Rs = .Execute(sSQL)
End With

ActiveCell.Offset(4, 4).Select

If Not (Rs.BOF And Rs.EOF) Then
For Each MyField In Rs.Fields
ActiveCell.Value = MyField
Next MyField
End If

End Sub

Many thanks for your expertise!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Code:
"WHERE ( (qryCSRPT_Funded_Subquery.created >= #" & Range("S2") & "#) And (qryCSRPT_Funded_Subquery.FundDate >= #" & Range("S4") & "# ));"
 
Upvote 0

Forum statistics

Threads
1,215,084
Messages
6,123,029
Members
449,092
Latest member
ikke

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