I have an excel with macros that fills a range of cells with a recordset obtained from SQL Server database. This excel is working fine since a bunch of months ago.
Now, I want to test XLsPadlock.
Setting this code in VBA compiler:
When trying to fill a cells range with the recordset obtained with:
returns this error:
Trying several options, without success.
¿Am I using “res” object correctly?
Now, I want to test XLsPadlock.
Setting this code in VBA compiler:
Code:
public sql_dataBase As String = "myDB"
public sql_serverIP As String = "myServerAddress"
public sql_passwordSA As String = "myPass"
public connStr As string = "Driver={SQL Server};Server=" & sql_serverIP & ";Database=" & sql_dataBase & ";UID=sa;Pwd=" & sql_passwordSA & ";"
Sub EXECsql(sql_command As String)
Dim cnn As Object
Set cnn = Application.CreateObject("ADODB.Connection")
Set cnn.ConnectionString = connStr
set cnn.Command = sql_command
cnn.Open
cnn.Execute
cnn.Close
Set cnn = Nothing
End Sub
'''''''''''''''''''''''''''''''''''''
Sub GETsql(sql_command As String)
Dim cnn As Object
Set cnn = Application.CreateObject("ADODB.Connection")
Set cnn.ConnectionString = connStr
cnn.Open
Dim rSetDades As Object
Set rSetDades = Application.CreateObject("ADODB.recordset")
set rSetDades.ActiveConnection = cnn
Set rSetDades.Command = sql_command
rSetDades.Open
' rSetDades.Close
''''''''''''''''''''''''''''''''''''''''''''''Set rSetDades = Nothing
cnn.Close
Set cnn = Nothing
End Sub
Code:
Dim res As Object
res = CallXLSPadlockVBA("GETsql", "SELECT [myField1], [myField2] FROM [myDB].[dbo].[myView]")
Sheets("mySheet").Range(myStartingCell).CopyFromRecordset res
Trying several options, without success.
¿Am I using “res” object correctly?
Attachments
Last edited:


