Function importFiles()
'function importFiles() imports the files using the import specs
'because of Access' limitations in regards to importing to linked tables, a local table
'is used to import to, and the data in it is then appended to the linked table
Dim fol As String 'starting folder path
fol = "V:\Corp\ACCT\900220\CC\Post Audit\Download Info\VCB RGM Detail\" _
& Format(Now, "yyyy-mm-dd"
'******************************************************************************************'
'RGM Merch detail
'Delete the information from the previous import
DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE tblRGMMchDetailImport.* FROM tblRGMMchDetailImport"

DoCmd.SetWarnings True
'Import
DoCmd.TransferText acImportFixed, "Rgmmch Import Specification", _
"tblRGMMchDetailImport", fol & "\rgmmch.txt"
'Delete the bad rows that come in from the first 32 rows of the file "XX etc."
DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE tblRGMMchDetailImport.CORP " & _
"FROM tblRGMMchDetailImport WHERE (((tblRGMMchDetailImport.CORP) Is Null))"
'query on the RGM number to ensure that the fields came in at the correct fixed width
Dim rgmMchResult
'should always be 1 if no errors
rgmMchResult = DCount("[Prefix]", "[qryRGMMerchPrefixGroupBy]"
If rgmMchResult = 1 Then
DoCmd.DeleteObject acTable, "rgmmch_ImportErrors" 'delete errors table
Else
MsgBox "There were errors in the conversion of rgmmch.txt, " & _
"check errors table and RGMMch table after import", vbCritical, "Import Errors"
On Error Resume Next
End If
'update vendor id field
DoCmd.OpenQuery "updateVndrIdTblRGMMchDetail"
'append import data to the linked table
DoCmd.RunSQL ("INSERT INTO tblRGMMchDetail ( CORP, RGM_NBR, RGM_DATE, VENDOR_NBR, " & _
"LOC, VENDOR_NAME, VOUCHER, PRO_NUMBER, COMMENT, SKU, QTY, MODEL_STYLE, UNIT_COST, " & _
"EXT_COST, COMMENT2, VNDR_ID )SELECT tblRGMMchDetailImport.CORP, " & _
"tblRGMMchDetailImport.RGM_NBR, tblRGMMchDetailImport.RGM_DATE, " & _
"tblRGMMchDetailImport.VENDOR_NBR,tblRGMMchDetailImport.LOC, " & _
"tblRGMMchDetailImport.VENDOR_NAME, tblRGMMchDetailImport.VOUCHER, " & _
"tblRGMMchDetailImport.PRO_NUMBER, tblRGMMchDetailImport.COMMENT, " & _
"tblRGMMchDetailImport.SKU,tblRGMMchDetailImport.QTY, tblRGMMchDetailImport.MODEL_STYLE, " & _
"tblRGMMchDetailImport.UNIT_COST,tblRGMMchDetailImport.EXT_COST, " & _
"tblRGMMchDetailImport.COMMENT2,tblRGMMchDetailImport.VNDR_ID FROM tblRGMMchDetailImport"
DoCmd.SetWarnings True
'********************************************************************************************'
'RGM Music detail
'Delete the information from the previous import
DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE tblRGMMusDetailImport.* FROM tblRGMMusDetailImport"

DoCmd.SetWarnings True
'Import
DoCmd.TransferText acImportFixed, "Rgmmus Import Specification", _
"tblRGMMusDetailImport", fol & "\rgmmus.txt"
'Delete the bad rows that come in from the first 32 rows of the file "XX etc."
DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE tblRGMMusDetailImport.CORP FROM " & _
"tblRGMMusDetailImport WHERE (((tblRGMMusDetailImport.CORP) Is Null))"
'query on the RGM number to ensure that the fields came in at the correct fixed width
Dim rgmMusResult
'should always be 1 if no errors
rgmMusResult = DCount("[Prefix]", "[qryRGMMusicPrefixGroupBy]"
If rgmMusResult = 1 Then
DoCmd.DeleteObject acTable, "rgmmus_ImportErrors" 'delete errors table
Else
MsgBox "There were errors in the conversion of rgmmus.txt, " & _
"check errors table and RGMMus table after import", vbCritical, "Import Errors"
On Error Resume Next
End If
'update vendor id field
DoCmd.OpenQuery "updateVndrIdTblRGMMusDetail"
'append import data to the linked table
DoCmd.RunSQL ("INSERT INTO tblRGMMusDetail ( CORP, RGM_NBR, RGM_DATE, VENDOR_NBR, LOC, " & _
"VENDOR_NAME, VOUCHER, PRO_NUMBER, COMMENT, SKU, QTY, MODEL_STYLE, UNIT_COST, EXT_COST, UPC, " & _
"VNDR_ID )SELECT tblRGMMusDetailImport.CORP, tblRGMMusDetailImport.RGM_NBR, " & _
"tblRGMMusDetailImport.RGM_DATE, tblRGMMusDetailImport.VENDOR_NBR, tblRGMMusDetailImport.LOC, " & _
"tblRGMMusDetailImport.VENDOR_NAME, tblRGMMusDetailImport.VOUCHER, tblRGMMusDetailImport.PRO_NUMBER, " & _
"tblRGMMusDetailImport.COMMENT, tblRGMMusDetailImport.SKU, tblRGMMusDetailImport.QTY, " & _
"tblRGMMusDetailImport.MODEL_STYLE, tblRGMMusDetailImport.UNIT_COST, tblRGMMusDetailImport.EXT_COST, " & _
"tblRGMMusDetailImport.UPC, tblRGMMusDetailImport.VNDR_ID FROM tblRGMMusDetailImport"
DoCmd.SetWarnings True
'*******************************************************************************************'
'VCB Merch Detail
'Delete the information from the previous import
DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE tblVCBMchDetailImport.* FROM tblVCBMchDetailImport"

DoCmd.SetWarnings True
'Import
DoCmd.TransferText acImportFixed, "Vcbmch Import Specification", _
"tblVCBMchDetailImport", fol & "\vcbmch.txt"
'Delete the bad rows that come in from the first 32 rows of the file "XX etc."
DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE tblVCBMchDetailImport.CORP FROM " & _
"tblVCBMchDetailImport WHERE (((tblVCBMchDetailImport.CORP) Is Null))"
'query on the VCB number to ensure that the fields came in at the correct fixed width
Dim vcbMchResult
'should always be 1 if no errors
vcbMchResult = DCount("[Prefix]", "[qryVCBMchPrefixGroupBy]"
If vcbMchResult = 1 Then
DoCmd.DeleteObject acTable, "vcbmch_ImportErrors" 'delete errors table
Else
MsgBox "There were errors in the conversion of vcbmch.txt, " & _
"check errors table and VCBMch table after import", vbCritical, "Import Errors"
' On Error Resume Next
End If
'update vendor id field
DoCmd.OpenQuery "updateVndrIdTblVCBMchDetail"
'append import data to the linked table
DoCmd.RunSQL ("INSERT INTO tblVCBMchDetail ( CORP, VCB_NBR, VCB_DATE, VENDOR_NBR, LOC, " & _
"VENDOR_NAME, VOUCHER, INVOICE_NUMBER, PO_NUMBER, COMMENT, SKU, QTY, MODEL_STYLE, " & _
"UNIT_COST, EXT_COST, COMMENT2, VNDR_ID )SELECT tblVCBMchDetailImport.CORP, " & _
"tblVCBMchDetailImport.VCB_NBR, tblVCBMchDetailImport.VCB_DATE, " & _
"tblVCBMchDetailImport.VENDOR_NBR, tblVCBMchDetailImport.LOC, " & _
"tblVCBMchDetailImport.VENDOR_NAME, tblVCBMchDetailImport.VOUCHER, " & _
"tblVCBMchDetailImport.INVOICE_NUMBER, tblVCBMchDetailImport.PO_NUMBER, " & _
"tblVCBMchDetailImport.COMMENT, tblVCBMchDetailImport.SKU, tblVCBMchDetailImport.QTY, " & _
"tblVCBMchDetailImport.MODEL_STYLE, tblVCBMchDetailImport.UNIT_COST, " & _
"tblVCBMchDetailImport.EXT_COST, tblVCBMchDetailImport.COMMENT2, " & _
"tblVCBMchDetailImport.VNDR_ID FROM tblVCBMchDetailImport"
DoCmd.SetWarnings True
'********************************************************************************************'
'VCB Music Detail
'Delete the information from the previous import
DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE tblVCBMusDetailImport.* FROM tblVCBMusDetailImport"

DoCmd.SetWarnings True
'Import
DoCmd.TransferText acImportFixed, "Vcbmus Import Specification", _
"tblVCBMusDetailImport", fol & "\vcbmus.txt"
'Delete the bad rows that come in from the first 32 rows of the file "XX etc."
DoCmd.SetWarnings False
DoCmd.RunSQL ("DELETE tblVCBMusDetailImport.CORP FROM " & _
"tblVCBMusDetailImport WHERE (((tblVCBMusDetailImport.CORP) Is Null))"
'query on the VCB number to ensure that the fields came in at the correct fixed width
Dim vcbMusResult
'should always be 1 if no errors
vcbMusResult = DCount("[Prefix]", "[qryVCBMusicPrefixGroupBy]"
If vcbMusResult = 1 Then
DoCmd.DeleteObject acTable, "vcbmus_ImportErrors" 'delete errors table
Else
MsgBox "There were errors in the conversion of vcbmus.txt, " & _
"check errors table and VCBMus table after import", vbCritical, "Import Errors"
On Error Resume Next
End If
'update vendor id field
DoCmd.OpenQuery "updateVndrIdTblVCBMusDetail"
'append import data to the linked table
DoCmd.RunSQL ("INSERT INTO tblVCBMusDetail ( CORP, VCB_NBR, VCB_DATE, VENDOR_NBR, " & _
"LOC, VENDOR_NAME, VOUCHER, INVOICE_NUMBER, PO_NUMBER, COMMENT, SKU, QTY, MODEL_STYLE, " & _
"UNIT_COST, EXT_COST, COMMENT2, VNDR_ID ) SELECT tblVCBMusDetailImport.CORP, " & _
"tblVCBMusDetailImport.VCB_NBR, tblVCBMusDetailImport.VCB_DATE, " & _
"tblVCBMusDetailImport.VENDOR_NBR, tblVCBMusDetailImport.LOC, " & _
"tblVCBMusDetailImport.VENDOR_NAME, tblVCBMusDetailImport.VOUCHER, " & _
"tblVCBMusDetailImport.INVOICE_NUMBER, tblVCBMusDetailImport.PO_NUMBER, " & _
"tblVCBMusDetailImport.COMMENT, tblVCBMusDetailImport.SKU, " & _
"tblVCBMusDetailImport.QTY, tblVCBMusDetailImport.MODEL_STYLE, " & _
"tblVCBMusDetailImport.UNIT_COST, tblVCBMusDetailImport.EXT_COST, " & _
"tblVCBMusDetailImport.COMMENT2, tblVCBMusDetailImport.VNDR_ID FROM tblVCBMusDetailImport"
DoCmd.SetWarnings True
End Function
I hope these two can help in some way.
Good Luck,
JR