New record only if the last record is filled

  • Thread starter Thread starter Luis Marques
  • Start date Start date
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
 
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.
 
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:
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top