error checking on contents of sub-form

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

Guest

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.
 
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
 
Thank you! That worked perfectly. It is also my first WITH (I am kind of
new at this).
 
Great! Learning and moving forward is the order
of the day - everyday ;-)
 

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