tatendatiffany
Board Regular
- Joined
- Mar 27, 2011
- Messages
- 103
I have a loop that runs through excel sheet column containing sql queries and display them in the next sheet. But i also want the loop after completing this column to run sql queries in another column and display results on sheet. This is what i have done so far :
Code:
Public Sub LoopQueries()
Dim i As Long
Dim MFcnn As New ADODB.Connection
Set MFcnn = New ADODB.Connection
With MFcnn
.Provider = "IBMDADB2.DB2COPY2"
.Mode = adReadWrite
.ConnectionString = "Password=" & password & ";Persist Security Info=True;User ID=" & username & ";Data Source=" & DatabaseEnv & ";Mode=ReadWrite;"
'.Open
Dim rsMFcnn As ADODB.Recordset
Set rsMFcnn = New ADODB.Recordset
Dim SQL As String
SQL = Sheet1.Range("AE2")
With rsMFcnn
.Open SQL
Sheet1.Range("AC2").CopyFromRecordset rsMFcnn
.Close
End With
cnMFcnn.Close
Set rsMFcnn = Nothing
Set cnMFcnn = Nothing
For j = 1 To 2
If (Sheet1.Cells(i, 1) = "") Then
j = 2
Else
j = 1
i = i + 1
End If
Next
End With
End Sub