New record only if the last record is filled

L

Luis Marques

What I need, is a code, that just alows to add a new record only if the last
record is filled.

Is it possible?

Thanks in advance
 
A

Arvin Meyer [MVP]

You should validate the last record and make sure it is filled before
allowing it to be saved. The easiest way is to add:

Is Not Null to the property sheet of every control on the form that you
require to be filled, but if they skip the controls entirely, you'll need
something like:

Public Sub CheckIt(frm As Form)
On Error Resume Next
Dim ctl As Control

For Each ctl In frm.Controls
With ctl
If .ControlType = acTextBox Or .ControlType = acCombobox Then
MsgBox "You MUST fill in" & ctl.Name, vbOKOnly, "Missing data"
End If
End With
Next ctl
Set ctl = Nothing
Set frm = Nothing

End Sub

Then call CheckIt in the BeforeUpdate event of your form.
 
L

Luis Marques

Yes, i'm doing this in a form.

I have 3 fields:
Employee
Time of Entrace
Time of Exit

What I need is a way to acess doesn't allow to add a new record if the field
"Time of Exit" is not filled.


"Jeff Boyce" escreveu:
 
A

Arvin Meyer [MVP]

In the BeforeUpdate event of the form, write some code like (untested):

Sub Form_BeforeUpdate(Cancel As Integer)

If Len(Me.[Time of Exit] & vbNullString) < 1 Then
MsgBox "You must Fill In the the Time of Exit", vbOKOnly, "Data Missing"
Me.[Time of Exit].SetFocus
Cancel = True
End If

End Sub
 
Top