Message Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I'm just starting to learn VBA programming, so at this point I know very
little. Here is my Question: If a user is filling out a form, and he/she
leaves one of the fields blank, and then clicks the Add New Record button, I
would like a message box to pop up and remind them that they have to fill out
the field they missed before they can add another record.

I tried using an If/Then statement:
If TextBox = "" Then
MsgBox("You must fill in the Date before proceeding",vbOKonly)
but it didn't work.

Any help would be greatly appreciated. Thanks

Lou
 
If you have a command button to add:
onclick event

if me.YourTextBox.value="" then
MsgBox "You must fill Date before proceeding"
else
... your statement
 
The code belongs in the Before Update event of the form. The issue you have
is that the default value of a control on a form (unless otherwise specified)
is Null. To stop the update, you use the Cancel argument of the Sub. That
is why we use the Before Update event. It can be canceled. The After Update
event is too late. Here is an example:

If IsNull(Me.TextBox) Then
MsgBox("You must fill in the Date before proceeding",vbOKonly)
Cancel = True
Me.DateTextBox.SetFocus
End If

Note. Always qualify your objects. That is, when you reference a control,
include what form it is on. If it is on the form where the code is, Me. or
Me! are shorthand for Forms!FormName
 
It worked...Thank You! I had been putting the code in the wrong place, I was
puttiing it in the AfterUpdate event of the command button. Thanks again

Lou
 
Back
Top