Can a Before Update proceedure be disabled?

WebFaktor

Registered User.
Local time
Today, 19:10
Joined
May 12, 2001
Messages
81
Is it possible via code to cancel the Before Update proceedure of a subform when a user wishes to exit the form/subform without saving their entries?

I have a main/sub form circumstance. Both the main and sub form have Before Update proceedures telling/asking users "Your entries are about to be saved. . ." When I exit from mainform without saving its entries the mainform's before update proccedure does not activate. Yet when I save the mainform records and move into the subform I cannot exit without the subform's Before Update proceedure activating???
 
Within this forum, at this posting:
http://www.access-programmers.co.uk/ubb/Forum4/HTML/004536.html

I located a circumstance similar to what I've described above. I'm still new enough at this to not understand how to implement the advice given. can any one help me with this puzzling matter?

Thank you, - Michael
_______________________________________
Declare a form level variable as boolean
On the Click event of the Button set the Variable = True

Before your message check the variable

if = False do the message box
if = True Exit Sub
 
Here is an example of some code I have on the BeforeUpdate event of a subform.

This makes sure that the user has filled out a specific field (RD_No) before moving off the form. If they don't complete it, they can say NO they want to undo the record:

Dim stdResponse As Integer
'If field not filled out then
If Me.RD_No = 0 Then
'give the user this message
stdResponse = MsgBox("You must select a repair before continuing." & vbCr & vbCr & _
"Do you want to continue?" & _
vbCr & vbCr & "Click YES to return to complete the record." & vbCr & vbCr & _
"Click NO to undo this entry.", vbYesNo, _
"Missing Data")
'if the user says yes, continue then return them to the field

If stdResponse = vbYes Then
Me.[RD No].SetFocus
End If
Exit Sub
End If
'if they say no, stop the before update and undo the record

Else
Cancel = True
Me.Undo
Me.Trade.SetFocus
End If


End If

Hope you can put that into your own setting. Post back if you have no luck

[This message has been edited by DBL (edited 03-15-2002).]
 
Hello,

I have a similar problem with a subform in datasheet view. In my case, in the subform BeforeUpdate, I check on the user input before he/she leaves the record.
My IF statement constraints are working fine and I then SetFocus to the offending control as noted in Dawn's post above.
Unfortunately and nevertheless, if the user had clicked on another record in the datasheet, the AfterUpdate event occurs, the focus is on another record and although I got out my message, the user is now free to ignore it and leave the subform later with incorrect data!
On a wild thought, I attempted the Me.Undo noted but the end result was still with the user on the next record.
If the purpose of the form BeforeUpdate event was to enable validation of the record's data, how do we leverage it by stopping the AfterUpdate event?
Any assistance or advice is appreciated! I will continue to search the threads.
 
Temp tables did the trick

Hello Sorrells,

Within the 'Access 97 Forms topics' (form sample database) check out the 'How to undo or rollback changes on main and subforms' topic. Setting up your temp tables is a bit of work, but well worth it. Once you get the hand of it, it's simple to duplicate for other similar circumstances.

Regards,

WF
 
Ah, the power of Knowledge. For how many years have I wondered what the function of (Cancel as Integer) as in
Private Sub Form_BeforeUpdate(Cancel As Integer)
could be. I am so happy that I can reply to my earlier questions with:
Add to your code
Cancel = True
if you want to stay in the same record.

Happy days are here again!
 
Thanks WebFaktor,

I think the 'Cancel' will handle this problem, I know it has for the first half of the validation but I had not thought of your approach and will keep this in mind as a similar challenge comes down the road!
 

Users who are viewing this thread

Back
Top Bottom