By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,056 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,056 IT Pros & Developers. It's quick & easy.

prevent closing a form and go to subform if no records in subform???

P: n/a
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....bd02708d914487
'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.Rec ordCount = 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

Apr 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
tlyczko wrote:
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....bd02708d914487
'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.Rec ordCount = 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

Maybe use the OnUnload event. Ask the user if they want to continue.
If so, delete their current record. If not, cancel = True.
Apr 16 '06 #2

P: n/a
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

Apr 16 '06 #3

P: n/a
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
"tlyczko" <tl*****@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
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

Apr 16 '06 #4

P: n/a
Thank you for posting the answer, this is the link to it for anyone who
is interested:

http://groups.google.com/group/micro...0c91f6d297f86c

Tom

Apr 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.