2 different outcome using the same bit of code?

megamef

Registered User.
Local time
Today, 19:45
Joined
Apr 18, 2013
Messages
161
Hi All,

I'm changing a record source on a form when the user clicks a "save" button.

I'm doing this to store a value from the current form in a table that is not part of the default form query.

This works fine.

I have a separate button on my form called "Home", when the user clicks this button it requerys the current form which triggers the before update event to run, this in turn brings up a message box which asks the user if they want to save or not. If they click yes then it runs the SaveButton click() code.

For some reason when the user presses the save button and then exits, everything works but if a user presses the “home” button which triggers the save button then it brings up the “2107 The Value you entered doesn’t meet the validation rule defined for the field or control.” Runtime error and stops on the change recordsource command.

I’ve no idea why triggering the same code directly from a button or indirectly from a before update event has two different outcomes.

Anyone know what’s going on?

Cheers

Steve
 
Last edited:
Can you post a copy of the database? - remove anything private; do compact repair and zip.
 
Sorry I can't really post the database as it's a bit of a monster and this is only a small part of it. I've now created a botch cure to the problem by which I ask the user to manually save the form before I allow them to exit which stops the before update triggering the code. Couldn't find out how to actually solve the problem though.
 
If I have this right, your home button is triggering a requery and a possible save all while the before update event is paused. My suggestion is to use before update with individual text boxes, not with an entire form. Get familiar with form.dirty. If it is true, the form has been changed, refresh the form, which puts any changes into the table. If dirty is false, just close the form, no changes. From a programming point of view, you need to handle all the saving stuff before you close the form and you seem to be doing the saving in the middle of closing it.
 
Sorry I can't really post the database as it's a bit of a monster and this is only a small part of it. I've now created a botch cure to the problem by which I ask the user to manually save the form before I allow them to exit which stops the before update triggering the code. Couldn't find out how to actually solve the problem though.

Could you post at least the SaveButton_Click code and the Before_Update event code ?

Best,
Jiri
 

Users who are viewing this thread

Back
Top Bottom