Run Append only once

Niniel

Registered User.
Local time
Today, 10:14
Joined
Sep 28, 2006
Messages
191
Hello,

On my main form, I have a combo box, and in its After Update event, I have
code to execute an append query.
It is intended as a one-time thing, to run when a new record is created, but
I just realized that it is easy to trigger this more than once, which then of
course messes up the database.
How can I ensure that the append operation is run only once?
Is there a way to check if the two tables that records are appended to
already have records with the main table's ID?

The target table/s have the following fields:

Table-specificID, MainTableID, CategoryID, and a few data fields.

Thank you.
 
If you only need to run it once per time the database is opened, then create a boolean public variable to set it to true when it is run and in the code to run the append query check to see if it is false and if so run it, if true don't.

If you need to run this query only once, period, or per day, etc., create a table to store a value that then you check to see if it is in there and the date. If the date is different, then you can let it run, if not then it can't.
 
Yes, Bob, I would like for this code to run once, and then never again because I'm using it to create new records in a child table based on the parent table's record ID.
So I figured I should try to check the table I am creating the records in for the existence of records with the current parent table's record ID.

What I don't know is how to do that.
Below is my SQL code that does the appending, maybe something can be done with that; or maybe I need something to do the checking before the code is run.

Since my knowledge of code is quite rudimentary and I haven't had such a situation before, I was hoping that somebody could show me how to do this. :)


strSQL = "INSERT INTO tblAnswers (RSCID, QuestionID) SELECT tblRSC.RSCID, tblQuestions.QuestionID FROM tblQuestions, tblRSC WHERE [RSCID] = " & Me.[RSCID]
 

Users who are viewing this thread

Back
Top Bottom