.Open source:=Src, ActiveConnection:=Connection

Now I have another problem.  I trying to apply this connection.

I get the connection but cant get info to pull in.  It stops at

 .Open source:=Src, ActiveConnection:=Connection

Error "The connection can’t be used to perform this operation.  It is either closed or invalid in this context."

Any help would be greatly appreciated.

''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Private conn As ADODB.Connection
Private Recordset As ADODB.Recordset


Public Sub OpenADO()
    Dim dbpath As String
    Dim Src As String
    Dim Connection As ADODB.Connection
    Dim Col As Integer
    Dim Recordset As ADODB.Recordset
    Dim As400 As Integer
    Dim A1 As Range
   
   
    'Without Password
    '  dbpath = "C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb"
   
    'With Password
   dbpath = "Data Source=\\Dtcnas-ilsp002\mandatory\Analysts - Working Files\Carol\Demo\Volume.mdb;Jet OLEDB:Database Password=OPPS;"



    Set conn = New ADODB.Connection
    With conn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .Open dbpath
    End With
   
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   
'   Create RecordSet
    Set Recordset = New ADODB.Recordset
    With Recordset
'       Filter
             
        Src = "SELECT [V05 CONV] ,[V05 GOVT], [Yes incentive] FROM [End_of_year_incentive] WHERE AS400 = " & TradeLimit.ComboBox1.Value

        .Open source:=Src, ActiveConnection:=Connection

'       Write the field names
        For Col = 0 To Recordset.Fields.Count - 1
           Sheet2.Range("a20").Offset(0, Col).Value = Recordset.Fields(Col).Name
        Next

'       Write the recordset
        Sheet2.Range("a21").Offset(1, 0).CopyFromRecordset Recordset
    End With
    Set Recordset = Nothing
    Connection.Close
    Set Connection = Nothing
End Sub
ca1358Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
Hi ca1358,

>  .Open source:=Src, ActiveConnection:=Connection

Change Connection to conn

Cheers!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you define conn AND connection, open conn, but use Connection !!


Option Explicit
Private conn As ADODB.Connection
Private Recordset As ADODB.Recordset


Public Sub OpenADO()
    Dim dbpath As String
    Dim Src As String
    Dim Col As Integer
    Dim Recordset As ADODB.Recordset
    Dim As400 As Integer
    Dim A1 As Range
   
   
    'Without Password
    '  dbpath = "C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb"
   
    'With Password
   dbpath = "Data Source=\\Dtcnas-ilsp002\mandatory\Analysts - Working Files\Carol\Demo\Volume.mdb;Jet OLEDB:Database Password=OPPS;"



    Set conn = New ADODB.Connection
    With conn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .Open dbpath
    End With
   
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   
'   Create RecordSet
    Set Recordset = New ADODB.Recordset
    With Recordset
'       Filter
             
        Src = "SELECT [V05 CONV] ,[V05 GOVT], [Yes incentive] FROM [End_of_year_incentive] WHERE AS400 = " & TradeLimit.ComboBox1.Value

        .Open source:=Src, ActiveConnection:=conn

'       Write the field names
        For Col = 0 To Recordset.Fields.Count - 1
           Sheet2.Range("a20").Offset(0, Col).Value = Recordset.Fields(Col).Name
        Next

'       Write the recordset
        Sheet2.Range("a21").Offset(1, 0).CopyFromRecordset Recordset
    End With
    Set Recordset = Nothing
    conn.Close
    Set conn = Nothing
End Sub
ca1358Author Commented:
Thank you!!!!!!!!!!
Guy Hengel [angelIII / a3]Billing EngineerCommented:
note that you should really clean up the code, because as it is right now, you would run into the next error on the line
>connection.Close
with the error: object variable not set ...
ca1358Author Commented:
Thank you for noting that.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.