well, let's see if i understand the situation. you're able to validate the
data in the main form to your satisfaction before the current record is
saved, and you're satisfied with how that's working for you, correct? but
you find that the user can enter data in the main form and then close the
form - without entering any records in the subform, correct? you want to
force the user to add at least one record to the subform, before closing the
main form - or moving to another record in the main form, correct?
well, that can get a little tricky - trying to force the user into adding a
record to a subform, while at the same time not boxing the user into a
situation where s/he has to add a record *even when it's not appropriate*.
i'd probably start out by trying the following:
add code to the main form's AfterUpdate event, to count the number of
records in the subform. if it's less than 1, move the focus to the subform,
and then to the first record in the subform. something like
Me!SubformControlName.Form.RecordsetClone.MoveLast
If Me!SubformControlName.Form.RecordsetClone.RecordCo unt < 1 Then
Me!SubformControlName.SetFocus
Me!SubformControlName!FirstControlInSubform.SetFoc us
End If
then check the recordcount again, on the subform control's Exit event, and
cancel the Exit if there are no records in the subform. something like
Me!SubformControlName.Form.RecordsetClone.MoveLast
If Me!SubformControlName.Form.RecordsetClone.RecordCo unt < 1 Then
Cancel = True
Msgbox "Enter a record in the subform, please."
End If
note that in both instances, the code is running in the *main* form, not the
subform. also, if there are no records in the subform, and yet you do *not*
get an error message when you click the Close command button, then you'll
have to put the AfterUpdate event code in the Close button's event
procedure, as well.
if you're not clear on the difference between a subform *control* and a
subform *form object*, go to
http://home.att.net/~california.db/instructions.html and click the
SubformControlName link for an illustrated explanation.
hth
<tlyczko@gmail.com> wrote in message
news:1145211357.180428.304120@z34g2000cwc.googlegr oups.com...[color=blue]
> Yes, I added this code to my btnClose OnClick event, and it appears to
> do what I need.
>
> I have one more question, if you (or someone else) don't mind.
>
> After I validate that the four fields have data in them, I do this
> code, to make sure they have entered the "right/correct" and I ask them
> to 'double-check':
>
> If MsgBox("The values you selected are:" & vbCrLf & _
> vbCrLf & Me.dtmReviewDate & vbCrLf & vbCrLf & _
> Me.txtReviewDescription & _
> vbCrLf & vbCrLf & Me.cboProgramID.Column(0) & vbCrLf & vbCrLf &
> Me.txtLocation & vbCrLf & vbCrLf & _
> "Are these correct? Do you want to add them?" & vbCrLf & _
> "Please be SURE before you add them." _
> , vbQuestion + vbYesNo, "Add to database?") = vbNo Then
> Cancel = True 'return to editing form, these values are not yet
> locked
> 'Exit Sub
> End If
>
> This all works very well...but it also makes it possible to close the
> form WITHOUT putting at least one record's worth of data (the visible
> fields) into this form's SUBFORM.
>
> Can I use similar BeforeUpdate code in the SUBFORM to ensure that I
> have data in the first two visible fields on the first new record the
> main form's subform?????
>
> If this isn't making any sense, please tell me...I'm now going to
> consult Access Hacks and Access Annoyances. :)
>
> Thank you, Tom
>
> P.S. You have a lot of stars by now!! :) :) You're very good at this.
> :) :)
>[/color]