2 sets of ADO connections to two different sheets in same procedure

farmergeoff2003

New Member
Joined
Jul 25, 2013
Messages
8
Hi, I am working on a procedure and just want to know if 2 ado connections are possible at once like this because I am getting an error that says "Object doesn't support this property or method" and the highlighted code is causing it but I know the field exists. Thanks!

Code:
Dim row As Integer
Dim col As Integer
Dim groupID As Integer
Dim strValue As String
strValue = vbNullString


Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1


Set wb = ActiveWorkbook
Set ws1 = wb.Sheets("ServerGroups")
Set ws2 = wb.Sheets("Servers")
Set ws3 = wb.Sheets("Display")


ws3.Unprotect


'open the ServerGroups sheet
Set conn1 = CreateObject("ADODB.Connection")
Set rs1 = CreateObject("ADODB.Recordset")


conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\Users\jmausolf\Desktop\SERVDBTESTING.xlsm;" & _
        "Extended Properties=""Excel 8.0;HDR=Yes;"";"
        
rs1.Open "Select * FROM [ServerGroups$]", _
    conn1, adOpenStatic, adLockOptimistic, adCmdText
        
'open the Servers sheet
Set conn2 = CreateObject("ADODB.Connection")
Set rs2 = CreateObject("ADODB.Recordset")


conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\Users\jmausolf\Desktop\SERVDBTESTING.xlsm;" & _
        "Extended Properties=""Excel 8.0;HDR=Yes;"";"
    
rs2.Open "Select * FROM [Servers$]", _
    conn2, adOpenStatic, adLockOptimistic, adCmdText

row = 1
col = 1
groupID = 1

Do Until rs1.EOF
ws1.Activate
   ws3.Cells(row, 1).Value = rs1.Fields.Item("Name")
   ws3.Cells(row, 2).Value = rs1.Fields.Item("Vendor")
   row = row + 1   ' Increase overall rows written to
   rs1.MoveNext
   ws2.Activate
   
   Do While rs2.Fields.Item("ID") = groupID
[COLOR=#ff0000]      ws3.Cells(row, 2).Value = rs2.Field.Item("Name")[/COLOR]
      ws3.Cells(row, 3).Value = rs2.Field.Item("Serial")
      ws3.Cells(row, 3).Value = rs2.Field.Item("Model/Type")
      row = row + 1
      rs2.MoveNext
   Loop
   
Loop
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

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