M
Mark
This code leaves Access open (can see it in task manager).
Is there a better way to close it? Am I leaving out a statement?
Thanks, Mark
Private Sub CommandButton3_Click()
'engineering projects import
Worksheets("PROJ").Range("A1:L50000").Clear
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim xlApp As Object
Dim xlWb As Object
Dim xlWs As Object
Dim recArray As Variant
Dim strDB As String
Dim fldCount As Integer
Dim recCount As Long
Dim iCol As Integer
Dim iRow As Integer
strDB = Worksheets("input").Range("B22")
Set xlApp = Application
Set ap = CreateObject("Access.Application")
ap.OpenCurrentDatabase (strDB)
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDB & ";"
xlApp.Sheets("PROJ").Select
rst.Open "Select * From [Seller Review]", cnt
Set xlWb = ActiveWorkbook
Set xlWs = xlWb.Worksheets("PROJ")
fldCount = rst.Fields.Count
For iCol = 1 To fldCount
xlWs.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name
Next
xlWs.Cells(2, 1).CopyFromRecordset rst
rst.Close
cnt.Close
Set ap = Nothing
Set rst = Nothing
Set cnt = Nothing
Set xlWs = Nothing
Set xlWb = Nothing
Set xlApp = Nothing
Sheets("INPUT").Select
End Sub
Is there a better way to close it? Am I leaving out a statement?
Thanks, Mark
Private Sub CommandButton3_Click()
'engineering projects import
Worksheets("PROJ").Range("A1:L50000").Clear
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim xlApp As Object
Dim xlWb As Object
Dim xlWs As Object
Dim recArray As Variant
Dim strDB As String
Dim fldCount As Integer
Dim recCount As Long
Dim iCol As Integer
Dim iRow As Integer
strDB = Worksheets("input").Range("B22")
Set xlApp = Application
Set ap = CreateObject("Access.Application")
ap.OpenCurrentDatabase (strDB)
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDB & ";"
xlApp.Sheets("PROJ").Select
rst.Open "Select * From [Seller Review]", cnt
Set xlWb = ActiveWorkbook
Set xlWs = xlWb.Worksheets("PROJ")
fldCount = rst.Fields.Count
For iCol = 1 To fldCount
xlWs.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name
Next
xlWs.Cells(2, 1).CopyFromRecordset rst
rst.Close
cnt.Close
Set ap = Nothing
Set rst = Nothing
Set cnt = Nothing
Set xlWs = Nothing
Set xlWb = Nothing
Set xlApp = Nothing
Sheets("INPUT").Select
End Sub