Link to home
Start Free TrialLog in
Avatar of jleval
jleval

asked on

Avoiding Null Values in Textbox

I have a text box and want to ensure that it is not left blank. This has to be done at the form level because the form I have is actually a dialog box that updates to another form once the information is entered.
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just add a check before the the update process.  Something like:
If IsNull(Me.TextBox) then
     MsgBox "This TextBox cannot be blank."
     Exit Sub
End If
Avatar of jleval
jleval

ASKER

Thank you
Why not use the Form BeforeUpdate event to validate this ? Then you do not have to worry about Tab stops.

mx
mx,

<< I have a text box and want to ensure that it is not left blank. >>

The reason I suggested the tab stop and the Exit event is that the BU event does not run if no edits have been made to the form.  If that is the only data entry control on the Popup form or if no other edits are made, the BU event alone would allow it to be left blank.  There are ways around that, such as setting the form's Dirty property in its Open Event, but as with the Exit event, it goes beyond simply validating the data.
"is that the BU event does not run if no edits have been made to the form.  "
Well, in which case, why would there be a need to validate anything ?

I would think a pop up of this sort would have a Save & Cancel button.
Avatar of jleval

ASKER

It has a cancel button but the save button is on the regular form. The reason I have this pop up form is to ensure that some type of data is entered in the fields.
Is it working okay for you, or do you need it to behave differently when the cancel button is pressed?
Avatar of jleval

ASKER

What happens is that the fields that are to be updated are given a default value when the pop up form pops up. If the user presses the cancel button, the fields are tested for that default value. When that default value is present, it deletes that record. The solution that was given works for what I am working with