Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger Afterupdate although BeforeUpdate is Cancelled

Status
Not open for further replies.

1VBAnewbie

Technical User
Apr 5, 2008
8
US
I need to update two tables using two forms. (Subform is not an option in this application)

On form1 the user enters data to create a record in table1. Upon the user moving to another record or leaving the form, I check for pre-existence of the record. Regardless of existence, I want form2 to open so a new record can be created in table2.

Form_BeforeUpdate() event on form1 is used to check for the existence of the record in table1.

Form_AfterUpdate() event on form1 is used to open form2.

If the BeforeUpdate event runs to conclusion when a record exists, I receive an error message (rightfully so) in attempting to create a record with an existing primary key.

If I cancel the BeforeUpdate event upon discovering the existing record, the AfterUpdate event does not execute. (this of course makes sense but doesn't help my cause)

These are my objectives:
1. after entry of data on Form1, determine if a record in table1 exists
2. update/insert the record in table1 only if record does not exist
3. open form2 regardless of existence of record in table1

I am seeking assistance with how to accomplish objectives 2 & 3.
 
Why not use the before update event?

pseudo code:

[tt]If record exists then
cancel update
open form 2
move to new record on form 2
End if[/tt]
 
How are ya 1VBAnewbie . . .

If your going to [blue]open form2 regardless of the existence of record in table1[/blue], whats the point of using the [blue]After Update[/blue] event? Juust use the [blue]Before Update[/blue], demonstrated by [blue]Remou[/blue] . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top