views:

143

answers:

1

i am using Docmd.TransferText to import data from a text file into my access table.

i would like it to do the following:

  1. if the record already exists, then update it
  2. if the record does not exist then add it

how do i accomplish this?

currently i have this line:

DoCmd.TransferText acImportDelim, yesyes, "table3", "C:\requisition_data_dump.txt", True
A: 

You cannot do this with an import. You could use transfertext to link the data as a table and then run an update and an append query.

sSQL="UPDATE table3 INNER JOIN MyLinkedTable " _
    & "ON table3.ID=MyLinkedTable.ID " _
    & "SET table3.SomeField=MyLinkedTable.SomeField "
CurrentDB.Execute sSQL, dbFailOnError

sSQL="INSERT INTO table3 (ID,SomeField ) " _
    ="SELECT ID, SomeField FROM MyLinkedTable " _
    & "LEFT JOIN table3 " _
    & "ON table3.ID=MyLinkedTable.ID " _
    & "WHERE table3.ID Is Null "
CurrentDB.Execute sSQL, dbFailOnError
Remou
great can you post the code to do the update and append?
I__
actually im sorry i do not really understand how this is relevant to my question, im sure it is, but can u please explain
I__
What you have is two queries that do *exactly* what you mention in your next question. Where are you having the problem understanding?
Remou
got it thank you again
I__
btw remousky u would be a good teacher, have u considered a career in pedagogy?
I__
In what way is this answer deserving of a down vote, please?
Remou
i apologize, it's not at all deserving of a downvote, my daughter clicked it by accident
I__
hey please edit a few characters in your answer, and i believe i can change the vote
I__
again im really sorry about that
I__
remoushka i helped you with your other down voted answers, now you just have this one, and u wont have anymore as soon as u change it
I__
Do not worry about it, as long as I know.
Remou