HELP:invalid or un qualified reference

tt.viquel

New Member
Joined
Apr 14, 2011
Messages
30
could someone please help me i am getting this error " invalid reference on
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
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
nevermind i have figured out what i was missing but now i am getting an error "class factory cannot supply requested class" on
Code:
ActiveConnection.cnMFcnn
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,682
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top