473,757 Members | 10,007 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 3131
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
7018
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
8850
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
7701
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
7503
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
5388
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
6030
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
1846
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
3077
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
7116
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
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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,...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
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,...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
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
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.