could someone please help me i am getting this error " invalid reference on
the entire code loops through several columns putting values in another column on the worksheet( is is connected to a database)
Code:
.Open SQL2
the entire code loops through several columns putting values in another column on the worksheet( is is connected to a database)
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;"
.ActiveConnection = cnMFcnn
.Open
' THIS IS THE CONNECTION TO THE DATABASE
Dim rsMFcnn As ADODB.Recordset
Set rsMFcnn = New ADODB.Recordset
Dim SQL1 As String
SQL1 = Sheet1.Range("AG2")
With rsMFcnn
.Open SQL1
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
' THIS IS CONNECTION TO AMA4 RUNNING THROUGH ENTIRE COLUMN
Dim ja As String
i = i + 1
ja = "A" + CStr(i)
SQL2 = Sheet1.Range("AF2")
.Open SQL2
Sheet1.Range("AA2").CopyFromRecordset rsMFcnn
.Close
End With
For j = 1 To 2
If (Sheet1.Cells(i, 1) = "") Then
j = 2
Else
j = 1
i = i + 1
End If
Next
'THIS CONNECTS TO AM3 AND IS RUNNING THROUGHOUT THE COLUMN
i = i + 1
ja = "A" = CStr(i)
SQL3 = Sheet1.Range("AE2")
.Open SQL3
Sheet1.Range("AA2").CopyFromRecordset rsMFcnn
.Close
End With
For j = 1 To 2
If (Sheet1.Cells(i, 1) = "") Then
j = 2
Else
j = 1
i = i + 1
End If
Next
' THIS IS CONNECTION TO AMA3 RUNNING THROUGH ENTIRE COLUMN
i = i + 1
ja = "A" = CStr(i)
SQL3 = Sheet1.Range("AI2")
.Open SQL3
Sheet1.Range("AD2").CopyFromRecordset rsMFcnn
.Close
End With
For j = 1 To 2
If (Sheet1.Cells(i, 1) = "") Then
j = 2
Else
j = 1
i = i + 1
End If
Next
' THIS IS CONNECTION TO AM5 RUNNING THE ENTIRE COLUMN
i = i + 1
ja = "A" = CStr(i)
SQL4 = Sheet1.Range("AJ2")
.Open SQL4
Sheet1.Range("AE2").CopyFromRecordset rsMFcnn
.Close
End With
For j = 1 To 2
If (Sheet1.Cells(i, 1) = "") Then
j = 2
Else
j = 1
i = i + 1
End If
Next
'THIS IS CONNECTION TO AMA7 RUNNING IN ENTIRE COLUMN
End Sub