Help with subforms before update event and making sure button on main form executes a

rocket2011

New member
Local time
Today, 16:00
Joined
Feb 8, 2011
Messages
6
Hey there, I have one main form and 2 continuous subforms in my access project. All my forms have before update routine to check for null condition. The problem is i have a close button on my main form which works fine if the user clicks it while updating the main form. However once from the subform if the user clicks on this button, it does not execute the code since the subforms before update event keeps throwing the validation check error. How do i force the code behind my button to execute at all times??
---
regards angad
 
Do you mean the close button as in the X in the top right corner?

If so you could disable that button in the form properties and create a command button to close it.

That command button could then run VBA to do any checks which you want to do and only do DoCmd.close if no nulls are found.

If it's already a command button but it's not correctly seeing the subform as having been updated when the user has not moved focus out of the control in the subform you should be able to include an If statement to check the .IsDirty property of the subform which will tell the code whether there are unsaved changes.
 
cbrighton! you saved my day mate! Thanx a ton!! :) i had the x button disabled and my own close button and previously i did not use the before update routine of the subform instead tried to check it from the close cmdbutton, but i could never get my code to refer the subform correctly because the moment the first record is updated by the user the focus automatically shifts to the next row. I never thought of using the forms isdirty property!! damn!! i tried all sorts of other things such as moving the focus to the previous row, recordcount but ended up nowhere.

I am pretty sure with this my problem should be solved :D
 
No problem.

Hope it all goes well, if not come back and update us.
 
hey cbrighton, unfortunately there is no way out and i could not get my cmdbutton to function properly, since my button is on my main form, and my subforms are part of my main form with master/child links, the isdirty property of the subform will always return false since my button is on the main form and clicking it means i am moving focus away from the subform.. in short i have given up :( and planning on changing my design as per access limitations....
 
To confirm, do you want the subform before update event to be bypassed if the main form command button is clicked?

I am looking back at your first post and that's how it reads, but I can't wrap my head around why that would be. When I weas posting yesterday I believed the opposite to be true, it was not correctly firing the before update event if the command button was clicked.

Can you confirm which it is?
 
the thing is - if there is a problem with data in the subform - how do you want access to manage when you close the form.

a) discard the edits OR
b) prevent the close, and make you fix the error

that's what the problem is, probably, so you need to decide how to report (identify) and resolve the subform error
 
hey guys,
thanks a lot for your help and really sorry for replying this late... had been spending sleepless nights trying to improvise and find a solution to my problem, i wanted the user to have the ability to close or quit the form at any point he feels and not save the record but at the same time i had validation checks to see if any field was left null.. for the main form it was quite easy to have a before update routine for the form and quit anytime in between since records would not be saved. However for the subform, since the close button is on the main form, having a before update routine was causing problems with quitting the form using close button since u cannot shift focus out of the subform till all fields are updated.

cbrighton: thats right i wanted to bypass the before update event and force my close button code to execute, but then what u replied that time gave me another idea, since previously i did not have before update routine on my subform, and was trying to properly refer the subform fields using my close button to throw an error, but using the forms dirty property i did not realize, it would always be false since clicking my close button would mean shifting focus out of the subform.

gemma: thanx i thought of this too , having a error handler and capturing the before update error there and forcing my close button code to execute, but never really ended up implementing it since my knowledge is pretty limited in access and coding.

Nyways i have finally redesigned and improvised my application after going through pages and pages of code and solutions on the net :) instead of having before update event for my form, i have before update events on each control of the form and subforms, close button can be executed anytime and my code deletes the saved records from the table letting the user think, it did not get saved. If any user tries to end the application using task manager, his name would get captured in audit trail for that record, since i have a login form and employees table. In the edit mode for saved records, i am using temp tables to save the record the user is working on and if he quits in between, all the records are rolled back to old values in the form as well as the subform. Thanx to microsoft's solution for it. All in all the application works like a charm now :D

THANX AGAIN FOR ALL YOUR HELP AND RESPONSES :) and sorry for the huge reply lol
 
you sound like you have a very well engineered solution.

i would have thought you could have just done something simpler, like in the sub-forms validation event just have a waring saying

"the data in the subform is invalid, and will not be saved"

then just executing an "undo" statement.
 

Users who are viewing this thread

Back
Top Bottom