Hi,
PLEASE HELP ME
I'm new to vba. I need to connect to a sql server database and return that information into certain cells. I can return it into the first cell for one value but I'm having trouble looping...
(The column A contains usernames that I wish to search for in the Sql Server Db and The column G is where I want to return the timestamp if the username is found to have access to a certain application (This application value is stored in the cell G1) so I want to start entering values into G2 down to say G100)
Here is what I've come up with so far:
I was using the following code that works, which let me return one value into one cell, but I want it to continue entering values down the column.
I hope some-one can help me cause I am so stuck!!!
PLEASE HELP ME
I'm new to vba. I need to connect to a sql server database and return that information into certain cells. I can return it into the first cell for one value but I'm having trouble looping...
(The column A contains usernames that I wish to search for in the Sql Server Db and The column G is where I want to return the timestamp if the username is found to have access to a certain application (This application value is stored in the cell G1) so I want to start entering values into G2 down to say G100)
Here is what I've come up with so far:
Code:
Sub Go()
For Each Acell In vRange
vRange = Range("A2:A6").Value
vVmsApp = Range("ITSecG1").Value
If IsEmpty(Acell) Then
Else
vSelect = "Select [Timestamp] from dbo.vVms where Username = '" & Acell & "' and Application = '" & vVmsApp & "';"
Set objData = objconn.Execute(vSelect)
vRange.Value = objData(0)
'Debug.Print objData(0)
End If
Next Acell
End Sub
I was using the following code that works, which let me return one value into one cell, but I want it to continue entering values down the column.
Code:
vUsername = Range("ITSec!A2").Value
vVmsApp = Range("ITSec!G1").Value
vSelect = "Select [Timestamp] from dbo.vVms where Username = '" & vUsername & "' and Application = '" & vVmsApp & "';"
objconn.Open vConn
Set objData = objconn.Execute(vSelect)
If objData.EOF Or objData.BOF Then
Else
Range("ITSec!G2").Value = objData(0)
End If
I hope some-one can help me cause I am so stuck!!!