validating a field

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

Guest

I have a form with several subforms. I need to make sure that there is
something entered in the "Quantity Started" field on the main form. Is there
any way I can do this without taking away the navigation buttons and adding a
save button, putting the validation text in the save button, etc? 'Cause
this also means I would have to add in the functionality to look for a job
number if it already exists... and that can be a pain.

Thanks!
Seren
 
Simplest solution is to make it a required field:
1. Open the main form's table in design view.
2. Select the [Quantity Started] field.
3. In the lower pane, set Required to Yes.
Now Access will not save the record unless a value is entered.

If you do not wish to make it required--just give a warning message that the
user can override--use the BeforeUpdate event of the form. Access fires this
event just before the record is written to the table. You can cancel the
event to block the save:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[Quantity Started]) Then
If MsgBox("You left the Quantity Started blank. Continue
anyway?", _
vbYesNo+vbDefaultButton2) <> vbYes Then
Cancel = True
End If
End If
End Sub
 
Thank you! the if statement in the BeforeUpdate was what I was looking for :)

Seren
--
Always behave like a duck- keep calm and unruffled on the surface but paddle
like the devil underneath.


Allen Browne said:
Simplest solution is to make it a required field:
1. Open the main form's table in design view.
2. Select the [Quantity Started] field.
3. In the lower pane, set Required to Yes.
Now Access will not save the record unless a value is entered.

If you do not wish to make it required--just give a warning message that the
user can override--use the BeforeUpdate event of the form. Access fires this
event just before the record is written to the table. You can cancel the
event to block the save:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[Quantity Started]) Then
If MsgBox("You left the Quantity Started blank. Continue
anyway?", _
vbYesNo+vbDefaultButton2) <> vbYes Then
Cancel = True
End If
End If
End Sub
 
Back
Top