Hi everyone,
I'm currently working on a project where I want data taken from an excel table imported into an access database. The excel table cannot be linked to the access. This is the code I am currently using:
Sub AccImport()
Set cn = CreateObject("ADODB.Connection")
dbpath = Application.ActiveWorkbook.Path & "\PCN Database.accdb"
dbWb = Application.ActiveWorkbook.FullName
dbWs = Application.ActiveSheet.Name
scn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbpath
dsh = "[" & "exportdata" & "$]"
cn.Open scn
ssql = "INSERT INTO PCN Database([PCR NO:],[Product Code/Item Number],[Product Description/Item Description],[Extra Description],[Net Net Wgt/CS (Paper ONLY)],[New Product],[Current Product Change],[Product Discontinued],[Consumer],[Home & Office],[Private Label],[Service],[Street],[Shipping Container Code (if Bundle 1st 2 bxs are Zeros)],[Level 2 - Inner Poly/Wrap UPC (Multi Pack/Bundles)],[Level 1 - Inner Most Poly/Wrap UPC],[Plant NJ],[Plant VT],[Plant Outsourced],[Item Class],[Item Type],[Estimated Initial Production Date],[Size of Paper L x W *],[No of Sheets (UNSZ)],[Basis Weight*],[Noof Plies*],[Print and % *],[Paper Grade *],[Package/Selling Unit(PACKAGING SIZE)]"
ssql = ssql & "SELECT * FROM [Excel 16.0 ;HDR=YES;DATABASE=" & dbWb & "]." & dsh
cn.Execute ssql
End Sub
Thank you
I'm currently working on a project where I want data taken from an excel table imported into an access database. The excel table cannot be linked to the access. This is the code I am currently using:
Sub AccImport()
Set cn = CreateObject("ADODB.Connection")
dbpath = Application.ActiveWorkbook.Path & "\PCN Database.accdb"
dbWb = Application.ActiveWorkbook.FullName
dbWs = Application.ActiveSheet.Name
scn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbpath
dsh = "[" & "exportdata" & "$]"
cn.Open scn
ssql = "INSERT INTO PCN Database([PCR NO:],[Product Code/Item Number],[Product Description/Item Description],[Extra Description],[Net Net Wgt/CS (Paper ONLY)],[New Product],[Current Product Change],[Product Discontinued],[Consumer],[Home & Office],[Private Label],[Service],[Street],[Shipping Container Code (if Bundle 1st 2 bxs are Zeros)],[Level 2 - Inner Poly/Wrap UPC (Multi Pack/Bundles)],[Level 1 - Inner Most Poly/Wrap UPC],[Plant NJ],[Plant VT],[Plant Outsourced],[Item Class],[Item Type],[Estimated Initial Production Date],[Size of Paper L x W *],[No of Sheets (UNSZ)],[Basis Weight*],[Noof Plies*],[Print and % *],[Paper Grade *],[Package/Selling Unit(PACKAGING SIZE)]"
ssql = ssql & "SELECT * FROM [Excel 16.0 ;HDR=YES;DATABASE=" & dbWb & "]." & dsh
cn.Execute ssql
End Sub
Thank you