472,145 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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

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
4 2999
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
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
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
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.

Similar topics

3 posts views Thread by paquer | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.