Sub ExportDataFromWorkbookToAccess()
' Export data from an Excel 2003 workbook
' to a 2003 format Access database
Dim cn As Object, strQuery As String
Set cn = CreateObject("ADODB.Connection")
myDB = Worksheets("Tables+").Cells(7, "M").Value
ThisWB = "'" & ThisWorkbook.Path & "\" & ThisWorkbook.Name & "'"
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = myDB
.Open
End With
strQuery = "INSERT INTO [ADPUpload] " & _
"SELECT " & _
"""3MT""" & " as [Co Code], " & _
"""KCOM""" & " as [Batch ID], " & _
" ADPNum as [File #], " & _
"CostCenter as [Temp Dept], " & _
"""I""" & " as [Earnings 3 Code], " & _
"Commissions as [Earnings 3 Amount], " & _
"[Sales Rep] " & _
"FROM [Detail+$] " & _
"IN " & ThisWB & " 'Excel 8.0;HDR=Yes;' " & _
"WHERE [Set of Books Id] = 1;"
cn.Execute "DELETE FROM ADPUpload"
cn.Execute strQuery
cn.Close
Set cn = Nothing
End Sub
|