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?
Thanks.
ming 12 12950
Open your subform's table in design view.
Select the foreign key field (the one that relates to the main form's
table.)
In the lower pane, set the Required property to Yes.
This prevents orphan records, but the user gets no message until they have
finished entering their record in the subform. You can also cancel the
subform's Before Insert event procedure:
Private Sub Form_BeforeInse rt(Cancel As Integer)
If Me.Parent.NewRe cord Then
Cancel = True
MsgBox "Enter the main form record first."
End If
End Sub
--
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.
"swingingmi ng" <mi******@gmail .com> wrote in message
news:11******** ************@g4 3g2000cwa.googl egroups.com... 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? Thanks. ming
swingingming <mi******@gmail .com> wrote: 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? Thanks. ming
Access by design will move to a new record at the end of a recordset on
a form. So its not a blank order, but a new order that doesn't exist as
a record until some information is entered (you'll see the little icon
in the left bar change).
You can stop this behaviour by turning off the Allow Additions property
of the form. But then you won't be able to add new records unless you
design a different way to do it.
--
regards,
Bradley
A Christian Response http://www.pastornet.net.au/response
Allen, thank you very much for your reply!!
Your solution sounds good, but I already set the foreign key to
required. And the record navigation button I am referring to is the
ones on the main form.
After I think more about it, I wanted to prevent the record on the main
form to stop saving if another weak entity (OrderDetails, foreign keys:
OrderID--from Orders table, and ProductID from Products table) is
empty. This maybe impossible in Access.
Regards,
ming
Thank you Bradley,
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.
Regards,
ming
swingingming <mi******@gmail .com> wrote: Thank you Bradley, 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. Regards, ming
Not sure how you'd do that as the record on the main form is saved when
it looses the focus to the subform.... and you can't add new records in
the subform until a record is saved in the main form anyway.
I probably missed this but why do you want to do it?
--
regards,
Bradley
A Christian Response http://www.pastornet.net.au/response
Thank you Bradley,
You are right about the saving when focus is lost on the subform. I
just think it doesn't make a lot of sense that an order without any
ordered items.
Ming
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.
--
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.
"swingingmi ng" <mi******@gmail .com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. . Allen, thank you very much for your reply!! Your solution sounds good, but I already set the foreign key to required. And the record navigation button I am referring to is the ones on the main form. After I think more about it, I wanted to prevent the record on the main form to stop saving if another weak entity (OrderDetails, foreign keys: OrderID--from Orders table, and ProductID from Products table) is empty. This maybe impossible in Access. Regards, ming
swingingming wrote: Thank you Bradley, 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. Regards, ming
One thing you can do is check for "itemless orders" at startup and prompt the
user so they can either be fixed or deleted.
This is another case where a form event that fired "before you leave" a record
would be handy, but there is no such event. The few times I have tried to
simulate one were partially successful. Basically you have to remove all built
in means by which the user can navigate and then supply your own. In the custom
navigation methods you could run a test for an order with no line items and
raise an error and NOT do the navigation in that circumstance. You would need
the same test in the Unload event.
The difficulty is in capturing all of the built in methods for navigation
without giving up a lot of desirable functionality.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
"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
event.
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc 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: 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...
|
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();...
|
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...
| |