Form validation

bluenose76

Registered User.
Local time
Today, 14:40
Joined
Nov 28, 2004
Messages
127
Hi,

I need a little help please with form validation.

My form is linked to a table for the purpose of recording vehicle details, owner, make, model, van etc....

I would like to have a button on my form that ensures all fields have been populated, confirms that the VRN does not already exist and then save the new record. (If the veh does already exist, then a pop up MSG saying so would be good)

Currently I have an on load function to ensure the form always starts with a lank record and it would be good for this to be the case once the new record has been added.

If anyone could help me with this, I would really appreciate it.

Thank you in advance for your help and suggestions.

Arran
 
Using VBA, cycle though all bound form controls, making sure each is populated. Controls which can have a null, empty or blank value will require extra coding to confirm valid entries.
 
Pat,

Thank you, I will give this a go tomorrow when I am near my machine again.

If we had access for the mac I woul never stop.

Regards,
Arran



Your validation code needs to go in the FORM's BeforeUpdate event. This is the last event to run before the record is actually saved and your code will cancel the event if it finds an error.
Code:
If Me.fld1 & "" = "" Then
    Msgbox "fld1 is required.  Please add a value.",vbOKOnly
    Me.fld1.SetFocus
    Cancel = True
    Exit Sub
End If
If Me.fld2 & "" = "" Then
    Msgbox "fld2 is required.  Please add a value.",vbOKOnly
    Me.fld2.SetFocus
    Cancel = True
    Exit Sub
End If
If Me.fld3 & "" = "" Then
    Msgbox "fld3 is required.  Please add a value.",vbOKOnly
    Me.fld3.SetFocus
    Cancel = True
    Exit Sub
End If
If fldx .............

Concatenating each value with a ZLS allows you to test for both nulls and "" at the same time.
 

Users who are viewing this thread

Back
Top Bottom