Hi Everyone.
I have a query in Access I'm trying to import to Excel, this will happen when i click on a userform button in excel.
This I have working.
Let me quickly explain my query, nice and easy, 2 columns, one "Usernames" second "Dates".
I thought right lets make this more useful, I want a criteria on my date field in the query to only show me dates which I select in a combo box in excel, so It will bring back my query into excel with the criteria based on the combo box.
In Access i went into query design and where it said criteria i typed:
[frmAg].[cboDates3]
frmAg is my form in excel
cboDates3 is my combo box
When I ran this query in access just to see what it did a pop up box asked me to enter a criteria, i did and it worked.
So for that part it's right, now bringing it back into excel how do I modify my code to accommodate my changes, below is the code I used to import my query but now I just get the error "No value given for one or more required parameters".
This is the excel code I use to import my query:
Sub queryAccess()
'Set the Microsoft ActiveX Data Object
'Use the Tools Menu and References search down for the above
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sQRY As String
Dim strFilePath As String
strFilePath = "C:\Users\Akrin\Desktop\Quality.mdb;" 'Database name and path
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFilePath & ";"
sQRY = "SELECT * FROM Usernames" 'Query name
rs.CursorLocation = adUseClient
rs.Open sQRY, cnn, adOpenStatic, adLockReadOnly
Application.ScreenUpdating = False
Sheet1.Range("A1").CopyFromRecordset rs 'Where to place the data
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
Exit Sub
End Sub
Any help would be much appreciated, thanks for your time everyone.
Bookmarks