I am new to VBA programming and I would like to run a pass-thru query (to SQL Server). I have the following code developed that compiles and executes without error, but I am not sure it does anything (at least not that I can see.
I run the code using a Macro without error, but also without result.
Public Function ExecuteSQL()
Dim sSQL As String
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
sSQL = "SELECT Top 10 dbo.tbl_pm_active.key_patient_2 FROM dbo.tbl_pm_active"
Set cn = New ADODB.Connection
cn.Open "DSN=DW_Vista" 'from ODBC setup
Set rs = New ADODB.Recordset
rs.Open sSQL, cn, adOpenDynamic
End Function
--
I run the same query in Access as a pass thru query and receive the ten records as planned:
This task is my starting point as I eventually want to use a local table as a filter for the individual records (Attached excel file).
Any suggestions would be appreciated.
I run the code using a Macro without error, but also without result.
Public Function ExecuteSQL()
Dim sSQL As String
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
sSQL = "SELECT Top 10 dbo.tbl_pm_active.key_patient_2 FROM dbo.tbl_pm_active"
Set cn = New ADODB.Connection
cn.Open "DSN=DW_Vista" 'from ODBC setup
Set rs = New ADODB.Recordset
rs.Open sSQL, cn, adOpenDynamic
End Function
--
I run the same query in Access as a pass thru query and receive the ten records as planned:
This task is my starting point as I eventually want to use a local table as a filter for the individual records (Attached excel file).
Any suggestions would be appreciated.