We help IT Professionals succeed at work.
Get Started

Create column during Access import

fizzlefry
fizzlefry asked
on
593 Views
Last Modified: 2012-05-11
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
LOOP

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"

Pause (2)

'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!"
End If

'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!"

End Sub

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.
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE