473,695 Members | 2,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.RunComma nd acCmdCloseWindo w
On Error GoTo Err_Handle

'4/16/06 try to ensure that a record is entered in subform, doesn't
work yet
If Me.fsubAddNewRe cordReviews.For m.RecordsetClon e.RecordCount = 0 Then
MsgBox "no records in subform"
End If

'4/16/06 ensure that BeforeUpdate validation code runs before closing
form
DoCmd.RunComman d 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 3126
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.RunComma nd acCmdCloseWindo w
On Error GoTo Err_Handle

'4/16/06 try to ensure that a record is entered in subform, doesn't
work yet
If Me.fsubAddNewRe cordReviews.For m.RecordsetClon e.RecordCount = 0 Then
MsgBox "no records in subform"
End If

'4/16/06 ensure that BeforeUpdate validation code runs before closing
form
DoCmd.RunComman d 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.goo glegroups.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7013
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which means showing all the data put in previously (ie showing this via the requery and the continuous...
4
8834
by: Macbane | last post by:
Hi, I have a 'main' form called frmIssues which has a subform control (named linkIssuesDrug) containing the subform sfrmLink_Issues_Drugs. A control button on the main form opens a pop-up form which allows me to edit the record in the subform. What I want to happen is for subform with the new edits to be updated on the main form when I close the popup. I'm sure this is a very small bit of code in the the 'On close' event for the popup...
3
7696
by: Darin | last post by:
I have a problem I just can't figure out. I have a form with a subform, and the recordsource of the subform has criteria based on some unbound fields in the parent form so that data in the parent form affects data in the subform. I've had this type of setup often, but I've run across a couple forms where this has caused an "enter parameter value" pop up for each reference to the parent control in the query when the main form is closed. ...
3
7501
by: bosmatthews | last post by:
I have a main form with a subform and a second subform nested to the first subform. The data entry property for all three forms (main, subform and sub-subform) is set to "yes" because I am intending this form to be used for data entry only. The main form has a combo box from which the user can select a lake. The first subform allows the user to enter survey data for the lake. The sub-subform allows the user to enter additional (plant...
3
5384
by: paquer | last post by:
On my Main form I have a Command Button that opens a Subform in order to create a new Subform record. At this point I want the subform to show only the new record being created. Not all the records the subform's table has. I cannot put the subform as Data Entry because I cannot print the main form & subform together if the subform is "data entry". (comes up blank every time)
6
6021
by: Otis492 | last post by:
Hello, I have been struggling with this for a while. I am working on a rather simple database for claims in Access 2003. I have a table called claims that has a primary key field called Claim #. It is linked to a table called parts. The idea is that a claim can be filed for multiple damaged parts. In other words a claim # could have 0 to several damaged parts. My problem lies with the form that I have created. It is a main form with a...
0
1844
by: jwbird | last post by:
I have a main form with multiple Subforms that are all displaying Datasheet information related to the Main form record. When I make changes/adds to the records(s) in the subform and tab to another subform, it saves those previous subform records fine, but when I make changes to the subform records and then change the mainform criteria, it doesn't save those subform records. I can use an event to prompt for saving the records on the...
2
3073
by: Gavin Sequeira | last post by:
Hi. I have a Main form with a Subform. My Main form generates an ID and some info is passed to the subform alongwith the ID. Lets say some changes are made to the mainform, this info is then added to the subform as a new record with the same ID (as in the main form) i.e saved as a 2nd record in my subform and will show under the main forms ID as 2 records. There are times when I have to generate the same values of the main form and capture the...
5
7110
by: jbrumbau | last post by:
Hello, I have some specification sheets with subforms I have created. I'm having a problem where if you right click and filter/sort any field in the subform (which is tied to the main form in a 1:1 relationship), then the subform only displays the first record. This ends up permanently altering the spec sheet. I notice that when this happens, text typically shows up in the "Order By" or "Filter" fields of the subform. My only resort is to...
0
8585
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8864
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3024
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2288
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.