Link to home
Start Free TrialLog in
Avatar of Hiken
HikenFlag for United States of America

asked on

Update an Id field on import of data with my own id from another table Using VB

What I'm currently doing is importing a text file.  The below code ImportTCN() works fine.  What I would like this code to also do is update the id field, which will be null, to a number from my id table something like this:  

 tTcn!ID = Nz(dmax ("ID","tID")) +1

Public Function ImportTCN()

Dim epath As String

    epath = DLookup("TCNImportLocation", "tSetDefaults")
    DoCmd.TransferText acImportFixed, "TCN Import Specification", "tTCN", epath, no

End Function




Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Public Function ImportTCN()

Dim epath As String

    epath = DLookup("TCNImportLocation", "tSetDefaults")
    DoCmd.TransferText acImportFixed, "TCN Import Specification", "tTCN", epath, no
 
'update the field
   currentdb.execute "update tTCN set [ID]=" & nz(dmax("ID","tID"))+1  & " where [ID] Is null"


End Function
Avatar of Hiken

ASKER

that is close, but what it is doing is only updating the last record.  It also picked the last id number out of the table and added one.  I changed it to dmin and it added 1 to it and made the last record 2.  What I need it to do is Update the first record to 001 next record to 002 etc.  
you should have specified that in your original post.
Avatar of Hiken

ASKER

sorry I didn't explain it well enough on the first
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hiken

ASKER

Thanks that did it