Required Textbox

  • Thread starter Thread starter Bryan Hughes
  • Start date Start date
B

Bryan Hughes

Hello,

I have a form that has two textbox that are required fields. How can I
prevent the user form leaving that textbox until something is entered?
Should I use an on Exit code?

If (IsNull(textbox) Or textbox="") Then
Cancel = True
Else
Cancel = False
End If

Something like this, or should I use something else?

-Bryan
 
Bryan:

Set the field value properties to "Required" and Do Not Allow Zero Length
Strings. Then in After Update and form Close events, you probably want to
test the contents of the text box for some form of sanity. Hopefully you
have some rules to apply
 
Use the Before Update event. It has a "Cancel" variable that can be set to
True to disallow the "leaving" of the textbox if the desired conditions are
not met.
 
Use the BeforeUpdate event to check if the fields are
filled in. If one or both are Null then warn the user
via a message box and then set the Cancel parameter of
the event to true. That cancels the update event and
leaves the focus on the form.

However, if the user closes the form (using the "x"
button, for instance), then you can get some really
confusing messages sent to the user. The solution to
that is to set the "Close Button" property to false and
include an exit button on the form (using the command
button wizard). Then modify the exit button code to save
the record before allowing an exit to take place. In
other words, only allow the exit if the forms' Dirty
property is false.
 
Back
Top