473,847 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: How to prevent moving to the new record when sub form is null?

Hi, in the NorthWind sample database, when clicking on the next
navigation button on the new order record with nothing on the subform
(order details), we got an order with nothing ordered. How can we
prevent this from happening?

Nov 13 '05
12 12972
"swingingmi ng" <mi******@gmail .com> wrote in
news:11******** **************@ g44g2000cwa.goo glegroups.com:
I think I didn't make myself clear. I want to be able to add new
records, but if there's no records on the subform, then I don't
want the records to be saved.

You seem to now be describing a problem different from the one
outlined in your subject.

The BeforeUpdate event of the parent form should be usable to check
if your subform has records, but, of course, you have to have a
parent record saved before you can enter child records.

My suggestion would be to make adding records doable only through a
command button, rather than allowing it through form navigation. The
New Record button would then check to see that you've created at
least one child record.

Likewise, you'd want to call the same verification code in whatever
navigation tools you use on the form. This means that you won't be
able to use the default Access navigation buttons unless you do what
I suggested in another message, setting the focus to the subform in
the main form's AfterUpdate event, then using the subform's OnExit
event to trap for no records in the child form.

David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #11
It probably is possible to force the focus into the subform in
Form_AfterInser t, and then use the Exit event of the subform control to
DLookup() the subform's table for a related record if the main form is not
at a new record.

There are several disadvantages of that approach, e.g.:
- Forcing focus into the subform regardless of how the record is saved in
the main form, and then not letting the user back out until they enter a
subform record would be quite confusing, I think.
- Can't use the subform's record count (it may be filtered), so it means
hitting the table with the DLookup() every time focus moves out of the
subform control.
- Without setting additional flags, can't know when exiting the subform
control whether the entry was as the result of a new main form record.
- If the user wants to kill the main form entry, they can't get out of the
subform to do so without dealing with the message about no related records.
It might be justified in some cases, but on balance I suspect the cure is
probably worse than the problem.

Additionally, there are problems in Access with connecting the subform
events and the main form's AfterUpdate event. I have a documented case where
the code in Form_AfterUpdat e works perfectly unless the record is saved by
moving into the subform. However, if the user tabs into the subform (which
triggers the implicit save of the main form's record) then:
- Access moves the form to a different record after Form_AfterUpdat e
completes, and
- the Enter event of the subform control fails to fire.

The particular case provided a number field for the user to reorder the
questions in a survey. In Form_AfterUpdat e, if this field changed, we
requeried the form in AfterUpdate (to reflect the new sort order), and moved
back to the record. This all worked fine unless the user tabbed into the
subform, in which case Access moved the main form to a different record
after Form_AfterUpdat e completed, and the Enter event of the subform never

While that's not directly related to this issue, I find it really scary when
the events are unreliable, and particularly where Access is moving the
record pointer after the events compete!

Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"David W. Fenton" <dX********@bwa y.net.invalid> wrote in message
news:Xn******** *************** *********@216.1 96.97.142...
"Allen Browne" <Al*********@Se eSig.Invalid> wrote in
news:42******** **************@ per-qv1-newsreader-01.iinet.net.au :
Kind of a chicken'n'egg problem.

You have to have the main record first, before you can create the
subform record. So you cannot make having a subform record a
condition for accepting the main form record.

The subject of the thread suggests a different problem to me, one
that should be able to be handled in the subform's OnExit event. In
order to go to a New record, you have to depart the existing record,
and that will force the OnExit of the subform, and in that, you
should be able to cancel that event if there's no child record,
which will in turn prohibit moving to a new record.

Now, the problem is forcing the OnExit event. That ought to be
doable by setting focus to the subform in the form's AfterUpdate

Nov 13 '05 #12
"Allen Browne" <Al*********@Se eSig.Invalid> wrote in
news:42******** **************@ per-qv1-newsreader-01.iinet.net.au :
It probably is possible to force the focus into the subform in
Form_AfterInser t, and then use the Exit event of the subform
control to DLookup() the subform's table for a related record if
the main form is not at a new record.

There are several disadvantages of that approach, e.g.:
- Can't use the subform's record count (it may be
filtered), so it means hitting the table with the DLookup() every
time focus moves out of the subform control.

Well, I disagree with that. You can check to see if the form is
filtered (i.e., .FilterOn = True) and *then* lookup the record count
only when it's filtered. Otherwise, you can use the
..Recordsetclon e's recordcount.

And, of course, I never use DLookup, but Trevor's tLookup.

As to your other points, after consideration, I agree that my
solution doesn't really work very well. I think the basic problem is
that the requirements are themselves rather flawed. The only way to
implement them is to completely control the Add and Save events, and
to disable default navigation methods in the form and provide your
own. You don't have to go unbound to get the control, you just have
to avoid the default behaviors.

David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: EqDev | last post by:
I have a class that is a control derived from UserControl. I want to use serialization and deserialization with this calss but I get an exception "Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface.". I am not interested in serializing any member from the base class only the properties in the derived class. How can I prevent the entire base class from being...
by: erick-flores | last post by:
Hello all My code used to work, but now its not working any more. What I am trying to do is find the current user when a forms open. This is the code that used to work: If faq_IsUserInGroup("Admins", CurrentUser) Then Me.RecordSource = "SELECT * FROM Employees" DoCmd.FindRecord (CurrentUser) <----------------------------------------------------
by: Ragbrai | last post by:
Howdy all, I have a form for entering data (Form A), on which is a cmd button that opens Form B in acdialog mode to allow me to enter/edit records that are being displayed on Form A. After adding/editing a record on Form B (opened in acDialog mode), I want a cmd button on Form B to close Form B and then have Form A automatically take me to the record that was added/edited in Form B (Form A has a subform that I will then enter data into). ...
by: AccessIdiot | last post by:
This is kind of an odd request. I have a form with a combo box. If an item isn't in the combo box you can add it by launching a new form (using NotInList). I would like for the main form to go right to a new record when the form is launched. I have code on the Load event that does this quite nicely. However, when the form to add to the combo box is launched and then closed it automatically causes the main form to advance to the next new...
by: solargovind | last post by:
Hi... Can anybody sugguest my below case..? When i open form either in Form View or Datasheet view, the form should come & stand current record. b'cos My user alter the data in previous record itself. Thanks in advance.. ngr..
by: Tom Clavel | last post by:
Scratching my head. I am using the filter property on a combo box .AfterUpdate event to get to a single client record. This is causing a some strange behavior: As I enter a subform, I get a no current record error. This is strange to me because: I can see the record contents displayed on the form, and debug.printing them gets me the values. Only the form.recordset is giving me this error. form.recordset .bof and .eof are false. ;...
by: MLH | last post by:
I've pretty much always applied a filter to a form to go to a specific record - filtering out all but the desired record. Am looking for code used to move to a specific record when keyfield value is known. This would leave my form in a state that PGUP and PGDN would still navigate up 'n down the dynaset. Seeking simplest methods.
by: teser3 | last post by:
I have my PHP inserting into Oracle 9i. But how do I prevent duplicate record entries? I only have 3 fields in the insert in the action page: CODE <?php $c=OCILogon("scott", "tiger", "orcl"); if ( ! $c ) { echo "Unable to connect: " . var_dump( OCIError() );
by: bkberg05 | last post by:
Hi -I have a form which contains a sub-form. The sub-form is tied to the main form by a shared field called Project_ID. The main form has one record per Project. The sub-form has many records per Project. When I'm adding Project records and go to a new record, the sub-form has no data in it. But then as soon as I type any data into the first field on the main form (after I type in the first character), the sub-form appears to populate...
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...
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,...
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...
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,...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.