E
elliottpt via AccessMonster.com
Hi
Currently I have a single form with a close button with the following code
attached to it( It is the default code generated from wizard for the close
button.)
Private Sub Close_Click()
On Error GoTo Err_Close_Click
DoCmd.Close
Exit_Close_Click:
Exit Sub
Err_Close_Click:
Msgbox Err.Description
Resume Exit_Close_Click
End Sub
I have vbCritical checks on all my fields on the on exit event to ensure the
correct data is entered.eg for the season field:
Private Sub Season_Exit(Cancel As Integer)
'Ensuring that the correct value is entered
If IsNull(Me.SEASON) Or Me.SEASON = "" Or Me.SEASON < 2008 Then
Msgbox ("Please enter the correct season"), vbCritical
Cancel = True
End If
End Sub
A problem arises when the user needs to exit and or abort the record. The
close does not give the user the option of exiting and overiding the
compulsory entry in the field; created by the vbCritical statement.
A MVP suggested the following code but 1stly I don't understand it, and 2ndly
it doesnt close the form.
if me.dirty then
'save record
me.dirty = false
end if
'if record could not be saved
if me.dirty then
if msgbox("OK to Close the form and discard edit on current record" _
& vbCrLf & " Cancel to return to record and make more changes"
vbOkCancel, _
"Abort " & iif(me.NewRecord,"New ","") & "record?") _
= vbCancel then
exit sub
end if
me.undo
end if
Some help would be much appreciated.
Kind regards
Philip
Currently I have a single form with a close button with the following code
attached to it( It is the default code generated from wizard for the close
button.)
Private Sub Close_Click()
On Error GoTo Err_Close_Click
DoCmd.Close
Exit_Close_Click:
Exit Sub
Err_Close_Click:
Msgbox Err.Description
Resume Exit_Close_Click
End Sub
I have vbCritical checks on all my fields on the on exit event to ensure the
correct data is entered.eg for the season field:
Private Sub Season_Exit(Cancel As Integer)
'Ensuring that the correct value is entered
If IsNull(Me.SEASON) Or Me.SEASON = "" Or Me.SEASON < 2008 Then
Msgbox ("Please enter the correct season"), vbCritical
Cancel = True
End If
End Sub
A problem arises when the user needs to exit and or abort the record. The
close does not give the user the option of exiting and overiding the
compulsory entry in the field; created by the vbCritical statement.
A MVP suggested the following code but 1stly I don't understand it, and 2ndly
it doesnt close the form.
if me.dirty then
'save record
me.dirty = false
end if
'if record could not be saved
if me.dirty then
if msgbox("OK to Close the form and discard edit on current record" _
& vbCrLf & " Cancel to return to record and make more changes"
vbOkCancel, _
"Abort " & iif(me.NewRecord,"New ","") & "record?") _
= vbCancel then
exit sub
end if
me.undo
end if
Some help would be much appreciated.
Kind regards
Philip