Openform problem

andrewf10

Registered User.
Local time
Today, 15:51
Joined
Mar 2, 2003
Messages
114
Hi folks,

I've been playing around VB for days now and I've gotten nowhere on this issue. Hopefully someone can help me:


On hitting a save button on Form 1, I need a Form 2 to open + check if the current ID number exists on it.
If not then create a new record (only the ID number) in this form
If it does exist, then don't add a new record


Can someone please help me?
Any help greatly appreciated, as ever

Thanks
 
The only way Form2 should have the same ID in it is as Form1 is if Form2 is the Many side of a One to Many relalationship and the ID in Form2 is the Foreign Key in Form2. If that is the case then Form2 should be a subform of Form1. If you do that then the ID will automatically be added to Form2 when a record is added to Form2....

hth,
Jack
 
Thanks for the reply Jack

Problem is, for all sorts of reasons it's not practical for Form 2 to be a Subform of Form 1. Also the nature and number of tables makes it an even greater mess. Just to complicate things, I'm using the fantastic MouseTrap code.

Can some of you experts please try looking at this very simplified sample database, open Form1 and type in a record and see what happens. All goes to plan except that somehow, the record on Form 2 won't save without an error. My head is wrecked from it

Thanks
 

Attachments

You need to rethink your approach. What you are doing doesn't make any sense. You should NOT be opening a form, placing values in controls and closing the form to add a record. If you want to add a record to another table, the correct way is with DAO/ADO or an append query. Lookup AddNew in help or in the archives here for sample code. Just be clear whether the code you're looking at is DAO or ADO. Either is fine.

The reason that your error is appearing is because Access is automatically saving the record in table2 when you close form2 and that causes the BeforeUpdate event to file. The save button of form2 was not pressed so your error message is displayed.
 

Users who are viewing this thread

Back
Top Bottom