T
tlyczko
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...es*+author:tina&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
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...es*+author:tina&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