Notiophilus
Registered User.
- Local time
- Today, 11:49
- Joined
- Jan 18, 2015
- Messages
- 42
I have a bound parent form with two subforms. If the user tries to leave a record without having entered certain key data (title, summary, link), the form challenges them: they can either cancel and stay on the record to enter the missing data, or keep going, and the incomplete record will be deleted.
My problem is that switching to a subform triggers BeforeUpdate (and thus the validation). How can I get around it?
There are several points on my form where I might need to force a save (e.g. to create a child record). If this happens, I set a flag in an unbound textbox
Unfortunately this doesn't work for the subforms, as the subform control Enter event happens after BeforeUpdate.
I think I'm at a dead end here. Is there an event that happens between clicking on / tabbing to fsubSubformControl and BeforeUpdate firing? Can anyone suggest a better way of doing things?
(I can sort of get around it by making a custom messagebox with options "keep editing" [cancel = true], "discard current record" [undo or delete record], "proceed" [exit sub and ignore validation]. I just don't like this option very much.)
Edited to fix brainfart in code - BeforeUpdate(Cancel As Integer)
My problem is that switching to a subform triggers BeforeUpdate (and thus the validation). How can I get around it?
Form_Dirty > [click or tab to the subform] > Form_BeforeUpdate (validation check) > fsubSubformControl_Enter
There are several points on my form where I might need to force a save (e.g. to create a child record). If this happens, I set a flag in an unbound textbox
txtAllowSave
, and use this to get around validation:SomeEvent forcing a save [set txtAllowSave = "yes"] > BeforeUpdate [if txtAllowUpdate = "yes", skip validation] > AfterUpdate > return to SomeEvent
Unfortunately this doesn't work for the subforms, as the subform control Enter event happens after BeforeUpdate.
Code:
Private Sub SaveWithoutValidation
'Force a save without triggering the validation in BeforeUpdate.
Me.txtAllowSave = "yes"
Me.txtTitle.SetFocus
Me.Dirty = True
Me.Dirty = False 'triggers BeforeUpdate
Me.txtAllowSave = "" 'after the save, reset, so that incomplete records will still be challenged on exit.
Me.Dirty = True
End Sub
Form_BeforeUpdate (Cancel As Integer)
If Me.txtAllowSave = "yes" Then Exit Sub 'skip validation and save as normal
If [key fields are OK] Then Exit Sub
Select Case msgbox "Key fields are empty. The record will not be saved. Proceed?" Then
Case vbNo
Cancel = True 'abort whatever triggered the update and keep editing
Case vbYes
'if it's a new record, undo it, otherwise delete
End Select
End Sub
Private Sub ThisEventForcesASave
If msgbox "create a child?" = true Then
Call SaveWithoutValidation
'create a child
End If
End Sub
I think I'm at a dead end here. Is there an event that happens between clicking on / tabbing to fsubSubformControl and BeforeUpdate firing? Can anyone suggest a better way of doing things?
(I can sort of get around it by making a custom messagebox with options "keep editing" [cancel = true], "discard current record" [undo or delete record], "proceed" [exit sub and ignore validation]. I just don't like this option very much.)
Edited to fix brainfart in code - BeforeUpdate(Cancel As Integer)
Last edited: