I have been looking on the NGs and I found this code to show if a
subform has no records.
I have this code in the MAIN form OnClose event:
Private Sub btnClose_Click()
'4/16/06 new code that cancels the close event if the BeforeUpdate code
fires
'4/16/06 see
http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/110755
9658a6541d/54bd02708d914487?lnk=st&q=DoCmd.Close+group%3Acomp.databases*+author%
3Atina&rnum=1&hl=en#54bd02708d914487
'DoCmd.RunCommand acCmdCloseWindow
On Error GoTo Err_Handle
'4/16/06 try to ensure that a record is entered in subform, doesn't
work yet
If Me.fsubAddNewRecordReviews.Form.RecordsetClone.RecordCount = 0 Then
MsgBox "no records in subform"
End If
'4/16/06 ensure that BeforeUpdate validation code runs before closing
form
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close , , acSaveNo
Err_Exit:
Exit Sub
Err_Handle:
Select Case Err.Number
Case Not 2501
MsgBox Err.Number & " " & Err.Description, "Unknown error"
End Select
End Sub
What I *want* to do is either here or in the MAIN form BeforeUpdate
event or in SOME event, ensure that the SUBFORM has at least one record
created, I don't want the main form to be closed without telling the
end user to fill in the fields in the SUBFORM.
So far all I have found is the above way to know that the main form has
no records.
Both the main form and subform are bound forms, this is not going to
change.
All I need is to prevent the main form from closing if the subform has
no records.
Thank you, Tom
salad - 16 Apr 2006 22:44 GMT
> I have been looking on the NGs and I found this code to show if a
> subform has no records.
[quoted text clipped - 45 lines]
>
> Thank you, Tom
Maybe use the OnUnload event. Ask the user if they want to continue.
If so, delete their current record. If not, cancel = True.
tlyczko - 16 Apr 2006 23:18 GMT
I think I tried that already...I will try again, though.
However I do not want to delete the current record from the main form.
I want to ensure that the end user ADDS a record to the SUBform.
Thank you, Tom
tina - 16 Apr 2006 23:59 GMT
Tom, i already posted an answer in your other thread on this same question,
started earlier today in this same NG. please don't multipost (see
http://home.att.net/~california.db/tips.html#aTip10 for more information),
and please cultivate a realistic expectation of response time in these NGs.
hth
> I think I tried that already...I will try again, though.
>
[quoted text clipped - 3 lines]
>
> Thank you, Tom
tlyczko - 17 Apr 2006 12:00 GMT
Thank you for posting the answer, this is the link to it for anyone who
is interested:
http://groups.google.com/group/microsoft.public.access.forms/tree/browse_frm/thr
ead/bffbeccf25fbcad0/585a090d9a4b9ec2?rnum=1&_done=%2Fgroup%2Fmicrosoft.public.a
ccess.forms%2Fbrowse_frm%2Fthread%2Fbffbeccf25fbcad0%2F585a090d9a4b9ec2%3Ftvc%3D
1%26#doc_330c91f6d297f86c
Tom