I
IanC
Hi
I'm trying to write some code which will force the user to complete a
particular field before exiting a new record on a form. In the BeforeUpdate
event for the form I used the following:
If RequiredField.Value = "" Or IsNull(RequiredField.Value) Then
MsgBox "Please complete the XXX field"
RequiredField.SetFocus
Cancel = True
NoErrors = False
Exit Sub
Else
NoErrors = True
End If
In the Unload event I used the following:
If NoErrors = False Then
Cancel = True
End If
Exit Sub
NoErrors is a global variable which is set to True in the Current event.
If the user tries to navigate to another record this works fine (with the
addition of some error handling). If the user tries to close the form it
works OK in terms of stopping the incomplete record being added, but when the
user is returned to the form the fields they had already completed have now
been left blank, so they've got to fill the whole form in again, and not just
the offending field. Is there any way of cancelling the BeforeUpdate event
without losing the already added data?
The only workarounds I've found are either to use the AfterUpdate event
instead, and force the user to delete the new record if they want to move
away from it, or to use a "Close" button instead of BeforeUpdate and get rid
of the X control. I know the latter is many people's favoured option but I
prefer to keep the X contol if possible since it is intuitive for users.
Surely there has to be a simpler answer?
Thanks
Ian
I'm trying to write some code which will force the user to complete a
particular field before exiting a new record on a form. In the BeforeUpdate
event for the form I used the following:
If RequiredField.Value = "" Or IsNull(RequiredField.Value) Then
MsgBox "Please complete the XXX field"
RequiredField.SetFocus
Cancel = True
NoErrors = False
Exit Sub
Else
NoErrors = True
End If
In the Unload event I used the following:
If NoErrors = False Then
Cancel = True
End If
Exit Sub
NoErrors is a global variable which is set to True in the Current event.
If the user tries to navigate to another record this works fine (with the
addition of some error handling). If the user tries to close the form it
works OK in terms of stopping the incomplete record being added, but when the
user is returned to the form the fields they had already completed have now
been left blank, so they've got to fill the whole form in again, and not just
the offending field. Is there any way of cancelling the BeforeUpdate event
without losing the already added data?
The only workarounds I've found are either to use the AfterUpdate event
instead, and force the user to delete the new record if they want to move
away from it, or to use a "Close" button instead of BeforeUpdate and get rid
of the X control. I know the latter is many people's favoured option but I
prefer to keep the X contol if possible since it is intuitive for users.
Surely there has to be a simpler answer?
Thanks
Ian