Hi everyone, I have this code that calls a query from my access database. The issue is that I need to call a query with 2 parameters, how can I add this to the code?
Thanks in advance
Thanks in advance
VBA Code:
Sub test111()
Const cstrPath As String = "C:\Data.mdb"
Const cstrQuery As String = "View_qry"
Dim dbe As Object 'DAO.DBEngine '
Dim rs As Object 'DAO.Recordset '
Dim ws As Worksheet
Application.DisplayAlerts = True 'leave alerts on during testing '
Set dbe = CreateObject("DAO.DBEngine.120")
Set rs = dbe.OpenDatabase(cstrPath).OpenRecordset(cstrQuery)
For i = 0 To rs.Fields.Count - 1
Sheets("Sheet1").Cells(1, i + 1) = rs.Fields(i).Name
Next i
If Not rs.EOF Then
Set ws = ThisWorkbook.Sheets("Sheet1")
ws.Range("A2").CopyFromRecordset rs
End If
rs.Close
Application.DisplayAlerts = True
End Sub