I am creating a reporting program in Access 2007. I have a ASCII flatfile that I need to break-up and import into Access. The file is a mixture of 4 pieces of information: wholesaler, retailer, sales, and items. What I need to do is report on the retailer sales, which is easy. But also I need to report on the wholesaler information. Currently, there is nothing in my 4 files that links back to the wholesaler. What I want to do is insert a column of text, in all 3 tables, that links to the wholesaler number (unique). Here's what I have:
My program to break-up my flatfile (thanks lewisq). This runs externally and is called to run from Access:
DIM strTemp AS STRING
OPEN "test" FOR INPUT AS #1
OPEN "HID.txt" FOR OUTPUT AS #2
OPEN "BID.txt" FOR OUTPUT AS #3
OPEN "SID.txt" FOR OUTPUT AS #4
OPEN "PUR.txt" FOR OUTPUT AS #5
DO WHILE NOT EOF(1)
LINE INPUT #1, strTemp
IF LEFT$(strTemp, 3) = "HID" THEN PRINT #2, strTemp
IF LEFT$(strTemp, 3) = "BID" THEN PRINT #3, strTemp
IF LEFT$(strTemp, 3) = "SID" THEN PRINT #4, strTemp
IF LEFT$(strTemp, 3) = "PUR" THEN PRINT #5, strTemp
CLOSE #1, #2, #3, #4, #5
My code in Access to handle the import (started by a button click):
Private Sub ffMulti_Click()
'runs my external program'
Shell "C:\MSA REPORT\TEST.EXE"
'dirty check to make sure it split the flatfile properly'
If Dir("C:\MSA REPORT\PUR.txt") <> "" Then
MsgBox "File Split Complete", vbOKOnly, "Done!"
Else: MsgBox "File Split Failed. Contact Support.", vbOKOnly, "Error!"
'imports my 3 separated text files'
DoCmd.TransferText acImportFixed, "BID Import Specification", "tblITEMS", "C:\MSA REPORT\BID.txt"
DoCmd.TransferText acImportFixed, "SID Import Specification", "tblRetailers", "C:\MSA REPORT\SID.txt"
DoCmd.TransferText acImportFixed, "PUR Import Specification", "tblSales", "C:\MSA REPORT\PUR.txt"
MsgBox "Flat File imported successfully.", vbOKOnly, "Done!"
The text value I need to insert in in the HID.txt file. My HID file contains something like:
HID00123456TOB W2011043Company Name... etc...
I need to take that number after HID, and insert it into an open column in my 3 tables that house retailer, sales, and item information (but it needs to be done at the time or either separation or import, so it's linked properly). I'm not sure what point would be the best to insert the text. I don't know if it would be better (or possible) to insert upon splitting the program or upon importing.
I could really use some expert help here. I would appreciate any and all help.