ca1358
asked on
.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:=Connecti on
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\No rthwind.md b"
'With Password
dbpath = "Data Source=\\Dtcnas-ilsp002\ma ndatory\An alysts - Working Files\Carol\Demo\Volume.md b;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:=Connecti on
' 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
I get the connection but cant get info to pull in. It stops at
.Open source:=Src, ActiveConnection:=Connecti
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\No
'With Password
dbpath = "Data Source=\\Dtcnas-ilsp002\ma
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:=Connecti
' Write the field names
For Col = 0 To Recordset.Fields.Count - 1
Sheet2.Range("a20").Offset
Next
' Write the recordset
Sheet2.Range("a21").Offset
End With
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!!!!!!!!!!
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 ...
>connection.Close
with the error: object variable not set ...
ASKER
Thank you for noting that.
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\No
'With Password
dbpath = "Data Source=\\Dtcnas-ilsp002\ma
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
Next
' Write the recordset
Sheet2.Range("a21").Offset
End With
Set Recordset = Nothing
conn.Close
Set conn = Nothing
End Sub