Hi,
Can anyone help me? I need to connect to a sql server database and return information into a column. I'm getting an error with this code - Object variable or with block variable not set
Here is what I've come up with so far with the help of a guy in another forum:
Can anyone help me? I need to connect to a sql server database and return information into a column. I'm getting an error with this code - Object variable or with block variable not set
Here is what I've come up with so far with the help of a guy in another forum:
Code:
Sub Return()
Dim vRange As Range
Dim Acell As Range
Dim ws As Worksheet
Dim vSelect As String
Dim vVmsApp As String
Dim SLottsRdInventoryPostAD As Workbook
Set ws = SLottsRdInventoryPostAD.Worksheets("ITSec") ' change to your sheet
vVmsApp = Range("ITSec!G1").Value
Set vRange = ws.Range("A2:A6")
For Each Acell In vRange
If Not IsEmpty(Acell) Then
vSelect = "Select [Timestamp] from dbo.vVms where Username = '" & Acell.Value & "' and Application = '" & vVmsApp & "';"
objconn.Open vConn
Set objData = objconn.Execute(vSelect)
Acell.Value = objData(0)
Debug.Print objData(0)
End If
Next Acell
End Sub