The following code is connecting to SQL and running a SQL queery. I works just fine. How do I store the data generated in the SQL queery to an Array in VBA?
Sub test()
Dim DSN As String
DSN = "Provider= ... ;Data Source= ... ;Initial Catalog= ... ;Integrated Security= ...;"
' I cannot share the name of databases and so on.
Dim Query1 As String
Dim Res1 As New ADODB.Recordset
Query1 = "select 1,2"
Set Conn = New ADODB.Connection
Conn.Open (DSN)
Set Res1 = Conn.Execute(Query1)
Sheet1.Range("A1").CopyFromRecordset Res1
Res1.Close
Conn.Close
End Sub
The code above is working perfectly and the values from SQL queery is being printed in A1 and B1. Now suppose I don't want to print it in my sheets but I want to store it in an VBA array. What do I do?
Bookmarks