POP UP Message - validation test

akhlaq768

Registered User.
Local time
Today, 19:36
Joined
Jan 17, 2008
Messages
42
Is it possible to check if the fields and drop down boxes are all complete before the records are submitted from the form?

I am using a COMMAND button on my form that will save the entries from the form into a database, but i want all the entries to be completed before it is submitted, so i want a pop up message to notify the user to complete all entries
 
yes, basic example:

Code:
sub button_click
  
  if me.sometextbox.value = "" then
    
    msgbox("A value for SomeTextBox must be entered")
    exit sub
  
  end if

   'run the query to insert the record
 
where do i put this code?

a newbie sorry
 
ive attached a sample of my form...
please could you assist in me writing the code for asking user to fill all entries before the form is submitted
 

Attachments

where do i put this code?

a newbie sorry

In design view on your form, right click on the submit button and choose Build Event, choose "code builder"

This should create the default "click" event handler for that button in the VBA editor. (i.e. what happens when the button is clicked)

So what now are the conditions that must be met for your submit button to actually submit data?

Is it enough that textboxSomething (and the other controls) has some data in it or should it be a particular type of data (ie a valid date, a number that's greater than 10 but less than 10000 etc).

Before you start trying to write any code, write out the process that should be followed once that button is clicked

eg.

1) I need to check that there is a value in txtboxes 1,2,3 and 4 If not, warn the user and exit
2) If textbox 2 isn't a Date that's greater than today's date it isn't valid, warn the user and and exit.

etc etc etc.

I can't download your form I'm afraid, but on a general basis that's how I'd start to approach validating the data.
 
can get the code to work correctly... can anyone assist please
 
ANSWER -

Private Sub btnNewOrder_Click()
Dim intanswer As Integer
If isNull(Forms!frmnavigation!cmbDistributionOrder) Then
intanswer = _
MsgBox("No Distribution selected, please select from list", vbInformation + vbOKOnly, "Select Distribution")

Else

Forms!frmnavigation.Visible = False
DoCmd.Minimize
DoCmd.openForm ("tblOrder"), acNormal, , , acFormAdd
End If
End Sub
 
A number of of things:

The syntax

if me.sometextbox.value = "" then

will not work! This code is only checking to see if the Control has a Zero-Length String ("") in it. It doesn't check for a Null, which is usually what a Control has if it is 'empty.'

Conversely

If isNull(Forms!frmnavigation!cmbDistributionOrder) Then

only checks for Nulls, not for Zero-Length String! To do both you'd use something like

If Nz(ControlName, "") = "" Then

Also, when referring a Control within the Code Module of the Form it resides on, instead of using

Forms!frmnavigation!cmbDistributionOrder

you can simply use

Me.cmbDistributionOrder

Your original post indicated that you wanted to check all Comboboxes and Textboxes on the Form, and you can do that with
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim ctl As Control

For Each ctl In Me.Controls
 If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
  If Nz(ctl, "") = "" Then
    Cancel = True
    MsgBox "The " & ctl.Name & " Field Must be Filled In!"
    ctl.SetFocus
    Exit Sub
  End If
 End If
 Next ctl

End Sub

Notice that this kind of Validation code has to be in the Form_BeforeUpdate event, not in the OnClick event for the Save button.

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom