error checking on contents of sub-form

S

SandyR

I have a form with a subform. I want to make sure that there is an entry in
a particular field of at least one linked record in the subform. This works
some of the time, but not others, depending on whether the user has clicked
on the empty record at the end of the subform. Here is my code:

If IsNull(frmaccountssubform.Form!account_number) Then
MsgBox "please enter an account number", vbOKOnly
checkforerrors = True
End If

How can I make sure that this looks at the first record of the sub-form at
all times? The code is in an on-click procedure for an update button. I
want to prevent the update if the field is blank.
 
M

Marshall Barton

SandyR said:
I have a form with a subform. I want to make sure that there is an entry in
a particular field of at least one linked record in the subform. This works
some of the time, but not others, depending on whether the user has clicked
on the empty record at the end of the subform. Here is my code:

If IsNull(frmaccountssubform.Form!account_number) Then
MsgBox "please enter an account number", vbOKOnly
checkforerrors = True
End If

How can I make sure that this looks at the first record of the sub-form at
all times? The code is in an on-click procedure for an update button. I
want to prevent the update if the field is blank.


I think this is waht you want"

With frmaccountssubform.Form.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
If IsNull(!account_number) Then
MsgBox . . .
. . .
Else
MsgBox "You must add a record first"
End If
End IF
End With
 
S

SandyR

Thank you! That worked perfectly. It is also my first WITH (I am kind of
new at this).
 
Top