Question about required fields, uniqe ID and save values

R

Robert

Need some help with the following problem. (Microsoft Access 2003)

I use a form as an interface for one table. An user must fill all fields and
at the end the application must create an unique ID (wrote VBA code to do
that).
Now i use a button to create the ID and save the values. But it also creates
a unique ID when not all fields are filled and when leaving a field Access
already saves the value from the previous field.
All fields are set to required in my table. So not filling in a field causes
a standard Access error message. But I don't like this kind of error
handling.
So I need some help to force that all fields are filled, the application
creates an ID and save the values.

Regards,

Robert
 
C

Carl

Have the code loop through the required input fields and is there is a null
field then msgbox(error) and exit the code prior to saving.
 
N

Nikos Yannacopoulos

Robert,

What you need is validation on the form controls before you get to the
saving part. The validation code could look something like:

For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Or _
ctl.ControlType = acComboBox _
Or ctl.ControlType = acOptionGroup _
Or ctl.ControlType = acListBox Then
If IsNull(ctl) Then
ctl.SetFocus
MsgBox "Pls fill in all values!", _
vbExclamation, "Required Data"
Exit Sub
End If
End If
Next

This will check all text boxes, list boxes, combo boxes and option
groups on your form, and if one is not populated it will put the cursor
to it, produce a message for the user and stop the execution of the
code, so no record save is attempted.

HTH,
Nikos
 
Top