Set up Alert

N

Natalia

I want to set up an alert on a form. If the user does not fill out all the
fields, they are prompted with a message - "You cannot continue until all the
fields are complete."
How can this be accomplished?

Thank you
 
J

Jeff

Natalia,

This can be accomplisehd by checking the .Value of each control in an event.

In the "Form Unload event" you can put code to check the value of each
control & then set the Form Property of "Cancel" = true so the form wont
unload.

So for example....

Private Sub Form_Unload(Cancel As Integer)

Cancel = False
If NameTextBox1="" then Cancel = True
If NameTextBox2="" then Cancel = True
If NameTextBox2="" then Cancel = True
If NameTextBox3="" then Cancel = True

' etc. put a check in for each control.

if Cancel = true then Msgbox "You cannot continue until all the fields are
complete."

End Sub


Regards,
Jeff
 
F

fredg

I want to set up an alert on a form. If the user does not fill out all the
fields, they are prompted with a message - "You cannot continue until all the
fields are complete."
How can this be accomplished?

Thank you

Why not set a validation rule for each of the controls:
Is Not Null

Or...
You can code the Form's BeforeUpdate event:

Dim c As Control
Dim intX As Integer

For Each c In Me.Section(0).Controls
If TypeOf c Is TextBox Or TypeOf c Is ComboBox Then
If IsNull(c) Then
intX = 1
Exit For
End If
End If
Next c

If intX = 1 Then
MsgBox "You cannot continue until all the fields are complete."
Cancel = True
End If

You may need to add listboxes, checkboxes, etc., to the TypeOf
statement above, if appropriate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top