Good day everyone, Im pretty new when it comes to VBA and Access so please bear with me.
I have this code that I found in the internet and modified it to fit my needs but it doesnt seem to work properly. It does import the excel spreadsheet to the "ImportTable" but it wont INSERT INTO the "Tbl_FundsData" and Im not really so sure about the WHERE NOT EXIST part.
What Im trying to accomplish is that a user can import an Excel Spreadsheet to Access on the temp table(ImportTable) first then to the main table(Tbl_FundsData). The WHERE NOT EXIST part is there to prevent duplicate data from inserting to the main table.
I really need help on this. Thank you in advance.
I have this code that I found in the internet and modified it to fit my needs but it doesnt seem to work properly. It does import the excel spreadsheet to the "ImportTable" but it wont INSERT INTO the "Tbl_FundsData" and Im not really so sure about the WHERE NOT EXIST part.
What Im trying to accomplish is that a user can import an Excel Spreadsheet to Access on the temp table(ImportTable) first then to the main table(Tbl_FundsData). The WHERE NOT EXIST part is there to prevent duplicate data from inserting to the main table.
I really need help on this. Thank you in advance.
Code:
DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "ImportTable", selectFile, True
DoCmd.SetWarnings True
Dim qrImp
qrImp = "INSERT INTO Tbl_FundsData([Reg], [Prov], [Mun], [Brgy], [NoSubProj], [SubProjTit], [FundSrc]," & _
"[Modal], [Cycle], [RecDate], [SubProj], [AppComGrants], [Rehab], [Taf], [LCCcashSPI]," & _
"[TotLCC], [TotProjCost], [GrantRel], [Trnch1], [Trnch2], [Trnch3], [Othrs], [BalRel]," & _
"[WvdExc], [BalRelExc], [GrantUti], [GrantBalUti], [LCCDel], [LCCUti], [LCCBalUti], [LCCDelUti]," & _
"[TotUti], [BalUti], [OthrRBPS], [RefRBPS], [BalRBPS], [RefDSWD], [RefLGU], [BalUtiRef]," & _
"[DVSubCOA], [NonDV], [BalSubCOA], [DVrpmo_srpmo], [DVact_bspmc], [PCFEst], [PCFLiq], [PCFBalLiq]," & _
"[CommOpn], [CommCls], [BalCls], [PhysAcc], [FinAcc])" & _
"SELECT [Reg], [Prov], [Mun], [Brgy], [NoSubProj]," & _
"[SubProjTit], [FundSrc], [Modal], [Cycle], [RecDate], [SubProj], [AppComGrants], [Rehab], [Taf]" & _
"[LCCcashSPI], [TotLCC], [TotProjCost], [GrantRel]," & _
"[Trnch1], [Trnch2], [Trnch3], [Othrs], [BalRel]," & _
"[WvdExc], [BalRelExc], [GrantUti], [GrantBalUti], [LCCDel]," & _
"[LCCUti], [LCCBalUti], [LCCDelUti], [TotUti], [BalUti]," & _
"[OthrRBPS], [RefRBPS], [BalRBPS], [RefDSWD], [RefLGU]," & _
"[BalUtiRef], [DVSubCOA], [NonDV], [BalSubCOA], [DVrpmo_srpmo]," & _
"[DVact_bspmc], [PCFEst], [PCFLiq], [PCFBalLiq], [CommOpn], " & _
"[CommCls], [BalCls], [PhysAcc], [FinAcc] FROM ImportTable" & _
"WHERE NOT EXISTS(SELECT Reg, Prov, Mun, Brgy, SubProjTit, RecData FROM Tbl_FundsData WHERE Tbl_FundsData.Reg And Tbl_FundsData.Prov And Tbl_FundsData.Mun" & _
"And Tbl_FundsData.Brgy And Tbl_FundsData.SubProjTit And Tbl_FundsData.RecData = Tbl_ImportTable.Reg And Tbl_ImportTable.Prov" & _
"And ImportTable.Mun And Tbl_ImportTable.Brgy And Tbl_ImportTable.SubProjTit And Tbl_ImportTable.RecData)"
DoCmd.RunSQL qrImp