Use tempvars to open a related form

All, got it sorted. Using Before_Update to validate data & if me.newrecord to add Fk. Will have a go with Before_Insert as an alternative approach to the if me.newrecord in the Before_Update event. Took me while to get my head round these important events. Thanks for the comprehensive answers.
 
Using Before_Update to validate data & if me.newrecord to add Fk.
Works, but as I said, not the best solution. Events are not random. The Access team didn't just throw "hooks" for you to into a bucket where you just pick the one whose name you like. EVERY event is targeted to doing certain things.

In my opinion, the BeforeUpdate event of the form is the most important form level event and there is never a form I create which allows updates that does not use the BeforeUpdate event. That doesn't mean that I would ignore more appropriate events such as the BeforeInsert event. This event runs as soon as the user types a single character. He has dirtied the record indicating his intent. Therefore, this is the best choice to run "once only" code like populating a FK. The event runs for EVERY new record, not just when the form opens. So, if you add multiple records after the form opens, they all get the correct FK. The technique that sets the default, I think is a little more obscure so I don't use it but it is correct in concept and so also an appropriate choice.

Here's a link to a database I created for a video about various Form and Control level events. There are three videos which will help you to understand events and what they are and how to use them. You can add your own forms to the database and as long as you use my logging code and have the log form open, you can see the events fire in your own form where it might make more sense to you.
 
@Pat Hartman , Thanks. Will watch the video & have a look at the database.
 

Users who are viewing this thread

Back
Top Bottom