473,769 Members | 6,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating "Orders" form

I hope not, but, I think the answer to this question is "it can't be done".

Northwind sample database. Orders form.

Go to a new record.
Select a customer in "Bill To:"
Don't enter any products whatsoever.
Now click or page up/down away from this new record.
You just created a new order without a single item having been ordered.
Not something a user should be able to do.

You would think that one could use the form's BeforeUpdate even to validate
the order. This would be true if the form did not contain any subforms.
However, in the case of "Orders" the subform gets in the way.

Another example of this is that you can go into any one order with multiple
ordered items and delete every single item in the order. Again, if you
could use Form_BeforeUpda te() to validate without ambiguity this could be
policed very nicely.

If you place validation code in the form's BeforeUpdate even this code will
also run when the use clicks or tabs through into the subform. And, as far
as I have been able to determine, there is no way to distinguish a
Form-to-Form BeforeUpdate event from a Form-to-Subform BeforeUpdate event.
This distinction, I think, is important.

So, here's the task: Make the Nothwind "Orders" form solid enough not to
allow faulty/incomplete orders to be entered into the database, either
through new entries or existing order modification. Where do you place the
code?
Thank you,

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Martin

To send private email:
x@y
where
x = "martineu"
y = "pacbell.ne t"


Jan 2 '06 #1
8 2046
Martin wrote:
I hope not, but, I think the answer to this question is "it can't be
done".


It can't be done. If you're concerned about it you can certainly make a routine
that will find any orders with no line items and delete them. Perhaps run this
whenever the form is closed.

At some point the user is always able to enter garbage.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Jan 2 '06 #2
"Martin" <0_******@pacbe ll.net> wrote in message
news:u9******** ********@newssv r11.news.prodig y.com...
I hope not, but, I think the answer to this question is "it can't be done".

Northwind sample database. Orders form.

Go to a new record.
Select a customer in "Bill To:"
Don't enter any products whatsoever.
Now click or page up/down away from this new record.
You just created a new order without a single item having been ordered.
Not something a user should be able to do.

You would think that one could use the form's BeforeUpdate even to
validate the order. This would be true if the form did not contain any
subforms. However, in the case of "Orders" the subform gets in the way.

Another example of this is that you can go into any one order with
multiple ordered items and delete every single item in the order. Again,
if you could use Form_BeforeUpda te() to validate without ambiguity this
could be policed very nicely.

If you place validation code in the form's BeforeUpdate even this code
will also run when the use clicks or tabs through into the subform. And,
as far as I have been able to determine, there is no way to distinguish a
Form-to-Form BeforeUpdate event from a Form-to-Subform BeforeUpdate event.
This distinction, I think, is important.

So, here's the task: Make the Nothwind "Orders" form solid enough not to
allow faulty/incomplete orders to be entered into the database, either
through new entries or existing order modification. Where do you place
the code?
Thank you,

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Martin

At 'table level' you cannot force an order to have at least one order item -
that is, the database table structure allows this. Therefore, you need to
restrict how users add a new order.
There is no quick fix for this application, but one technique you could look
at is unbound forms. For example, the orders form would no longer allow
simple additions, but you have a New Order button which pops up an unbound
form. Here you add the customer, product, quantity, etc and an OK button
will create an order with that one line item and then allow further line
items to be added in the subform.
Another possibility is temporary tables, where you create both the order and
the line items in tables TempOrder and TempItem and have an OK button on the
order form which checks everything is OK in both tables before committing
the data to the real tables.
Both of these possibilities may be more work and less fun than you had hoped
for, but both are techniques I have seen used with this sort of problem.

Jan 3 '06 #3
Anthony England wrote:
At 'table level' you cannot force an order to have at least one order
item - that is, the database table structure allows this. Therefore, you
need to restrict how users add a new order.
Understood. That's what I was hoping to do by only allowing a database
write (to any affected table) upon reasonable verification of minimum order
requirements. Yes, of course, users will make mistakes (mispellings, wrong
data, etc.). You should, however, be able to do a little more validation
than simply saying "oh well, I use a subform so I have to take an incomplete
order and live with it".
There is no quick fix for this application, but one technique you could
look at is unbound forms.


While I don't have a tremendous amount of experience with Access it is
starting to seem like it is a royal PITA. Controls that don't work
properly, ActiveX issues, and this matter of proper UI/data validation being
a few of the items I've run into so far. I'll continue to explore for a
little while longer. However, my current sentiment is that it would be much
more intelligent (and maybe even productive) to use VB6 to manage the UI
experience with unbound controls and then drive the database with
significantly improved solidity.

I am astounded that Access does not provide a mechanism to determine if a
BeforeUpdate event was triggered by intra-form navigation rather than
form-to-form navigation (among other things). Thinking out of the box for a
moment, a possible fix might be to write some code to be able to trap
relevant Windows messages before the form gets them. This would allow
setting a form-level variable to indicate what the user clicked with the
mouse or pressed on the keyboard. Checking this variable in
Form_BeforeUpda te() would then provide a mechanism to intelligently decide
what to do with the event.

I guess I can compromise and say that I don't have a problem with the table
corresponding to the "one" side of the form being updated. It would be nice
to not allow the user to leave the form unless the required "many" side/s
can be validated to a reasonable extent.

Thanks,
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Martin Euredjian
eCinema Systems, Inc.

To send private email:
x@y
where
x = "martineu"
y = "pacbell.ne t"
Jan 3 '06 #4
What is wrong with Rick's idea?
IMO it would be a PITA to write an app in VB6 because of this 'limitation'
You need to know the 'habits' of Access and treat Access like a lady ;-)

I have a similar app and simply check for Order details when I close the Orders form.
If no details ==> the record is deleted. (no confirmation but only a message)
I also check for details before I allow to leave the Record (e.g. navigation)
Also on startup I run a routine to simply delete all OrderRecs without details (without asking)
This is just to make sure ...

You could also use something like a global var to determine the last accessed ordersID.
On current: If no details present with last accessed ID ==> delete that record.

Arno R


"Martin" <0_******@pacbe ll.net> schreef in bericht news:7g******** ***********@new ssvr14.news.pro digy.com...
Anthony England wrote:
At 'table level' you cannot force an order to have at least one order
item - that is, the database table structure allows this. Therefore, you
need to restrict how users add a new order.


Understood. That's what I was hoping to do by only allowing a database
write (to any affected table) upon reasonable verification of minimum order
requirements. Yes, of course, users will make mistakes (mispellings, wrong
data, etc.). You should, however, be able to do a little more validation
than simply saying "oh well, I use a subform so I have to take an incomplete
order and live with it".
There is no quick fix for this application, but one technique you could
look at is unbound forms.


While I don't have a tremendous amount of experience with Access it is
starting to seem like it is a royal PITA. Controls that don't work
properly, ActiveX issues, and this matter of proper UI/data validation being
a few of the items I've run into so far. I'll continue to explore for a
little while longer. However, my current sentiment is that it would be much
more intelligent (and maybe even productive) to use VB6 to manage the UI
experience with unbound controls and then drive the database with
significantly improved solidity.

I am astounded that Access does not provide a mechanism to determine if a
BeforeUpdate event was triggered by intra-form navigation rather than
form-to-form navigation (among other things). Thinking out of the box for a
moment, a possible fix might be to write some code to be able to trap
relevant Windows messages before the form gets them. This would allow
setting a form-level variable to indicate what the user clicked with the
mouse or pressed on the keyboard. Checking this variable in
Form_BeforeUpda te() would then provide a mechanism to intelligently decide
what to do with the event.

I guess I can compromise and say that I don't have a problem with the table
corresponding to the "one" side of the form being updated. It would be nice
to not allow the user to leave the form unless the required "many" side/s
can be validated to a reasonable extent.

Thanks,


~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Martin Euredjian
eCinema Systems, Inc.

To send private email:
x@y
where
x = "martineu"
y = "pacbell.ne t"

Jan 3 '06 #5
Arno R wrote:
What is wrong with Rick's idea?
Take the example of an existing --and perfectly valid-- order being edited.
The user deletes all detail information and navigates away from the form.
Now you have a previously-good order that has retained the information on
the "one" side of the equation but has lost all data on the "many" side. If
you "auto clean" the DB and delete all orders that have no items, you just
added insult to injury. An order that was perfectly real was just cleansed
off the face of the planet. The user should have never been allowed to edit
away all detail data. If the intent was to delete the order, then a proper
and separate mechanism should be provided.

Of course, some sort of a multi-form/multi-state approach could be used to
slice-up the order entry and editing process so that you can police each and
every step of the way. Someone suggested using temporary tables, for
example. That's fine. There's always a work around. However, MS has loads
of form/subform examples that seem to suggest that this is an acceptable and
supported way to manage one/many type data entry. Which, of course, isn't
true because it opens the doors to a horrible mess.
IMO it would be a PITA to write an app in VB6 because of this 'limitation'
Most of the form/record management code can be nicely encapsulated into a
reusable class. The PITA is creating the forms and fine-tuning the UI.
But, that's true of any nicely tuned UI project. They take lots of work.
VB6 has nice advantages that I cannot understand why Access does not offer,
for example, control arrays. You save tons of coding by using them where
appropriate.
You need to know the 'habits' of Access and treat Access like a lady ;-)


Very true, that's why I am not going to give up just yet. It is painful,
however, to burn well over a week trying to figure out a work-around for
this form/subform BeforeUpdate problem and finally have to descend into
allowing bad records to be entered into the database. Not my idea of
elegance in design by a long shot.
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Martin Euredjian
eCinema Systems, Inc.

To send private email:
x@y
where
x = "martineu"
y = "pacbell.ne t"
Jan 3 '06 #6

"Martin" <0_******@pacbe ll.net> schreef in bericht news:6Q******** ********@newssv r25.news.prodig y.net...
Arno R wrote:
What is wrong with Rick's idea?
Take the example of an existing --and perfectly valid-- order being edited.
The user deletes all detail information and navigates away from the form.
Now you have a previously-good order that has retained the information on
the "one" side of the equation but has lost all data on the "many" side. If
you "auto clean" the DB and delete all orders that have no items, you just
added insult to injury.


I only "auto clean" because there still is a very slight chance that orphan records exist...
I understood you wanted to prevent orphan records...
An order that was perfectly real was just cleansed
off the face of the planet. The user should have never been allowed to edit
away all detail data. If the intent was to delete the order, then a proper
and separate mechanism should be provided.


It is up to *you* as the developer to provide such mechanism.

If the user wants to add records you can allow or deny that.
If you want to validate data before saving, you can do that
You can prevent the editing of the detailrecords from the subform if you like ...
You can validate each and every field while editing ....
You can also prevent the deletion of the detailrecords from the subform if you like ...
You can ask the user if he/she would want to delete and allow or prevent that ....

What more do you need?

Arno R
Jan 3 '06 #7
Arno R wrote:
If the intent was to delete the order, then a proper
and separate mechanism should be provided.
It is up to *you* as the developer to provide such mechanism.
That's what I said.

If you want to validate data before saving, you can do that
No you can't!

Take the Northwind database "Orders" form.
Validation rule: While using this form, the operator shall not be permitted
to enter an order into the system if the order does not contain any items.

I am using the Northwind database "Orders" form as an example that everyone
is likely to have on their computers. My application is not a product
ordering application but rather an engineering solution I am attempting to
fit into Access. There will be many forms with one/many relationships
handled with form/subforms for the UI. Clean and fully-validated data
records is a must.

If I was outsourcing the work to a consultant, the above validation rule
would have been in the specifications, without a doubt. Based on all
current indications, this counsultant wouldn't have a way to deliver this
without resorting to some pretty extensive girations.
What more do you need?


Just that, for now. :-)

Later today I am going to explore the idea of popping the user back into the
newly created record if the last record added to the database did not
contain detail items. Thinking out loud, this would probably have to be
added to the Form_OnCurrent( ) event along with (maybe) a global variable set
to the last record loaded onto the "one" side of the form. The code would
query for order items for the last order and, if none are found, pop the
user back to that record. Again, in Form_OnCurrent( ) a check would be made
for order items in the (now current) order and offer a dialog box providing
the option to either delete the order or add items to it.

That's the theory. I'll see how/if it works later tonight.

This, of course, is tenous in that it would have to allow the "one" side of
the order to be saved and then attempt to cleanup (delete) or complete the
"many" side of the order. If anything in the pop-back process is disturbed
(say it is a remote connection, or the user isn't interested) the bad
order's "one" side would now be saved to the corresponding table.

One other thought. Maybe I can add a boolean "OrderItemsEnte red" field to
Orders table. It would have a default value of "False". This would provide
for a much more solid way to determine if an order is valid. This field
would only be set to "True" upon entry of at least one item in the subform.
In my case there are more than one "many" tables related to what would be
the orders "one" side. Imagine if you had a table of phone calls and
another table of notes or history on each order. You could have multiple
order items, multiple call logs and multiple notes. Maybe even more than
one of these "many" relationships would require at least one entry for a
valid order. In this case, the Orders table would have one boolean flag for
each of the required "many" records.

A little messy, but there might be a way yet!
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Martin Euredjian
eCinema Systems, Inc.

To send private email:
x@y
where
x = "martineu"
y = "pacbell.ne t"
Jan 3 '06 #8
Northwind is not renowned for its exemplary practices. It's somewhere
between a shill and a trapeze act.
I suppose that you have identified a legitimate concern although I
don't pretend to have studied everything in this thread carefully.
Northwind was not on my computer but I donwloaded it so that I could
see just what you are telking about.

I !!!think!!! this is a sample of something about which I've argued
[it's hard to imagine my arguing but it has actually happened once or
twice!] and lost contracts. That is, should we go from the particular
to the general, from the child to the parent, or vice versa. I prefer
small first, large later. That is children have parents; parents do not
have children.

I believe my Orders form would simply be a list of products required. I
assume the DB and Access could decide from whom to order them, (I might
want to indicate a preference if an item were available from more than
one supplier), print an Order, and mark each record as having been
ordered. But the ORDER would have existence only in real-time, it would
be the printing of the Order report. We could keep information about
the Products, Date Ordered, Signing Authority, Budget Charged,
Cancelled, quite easily.

Ah, the regulars will say, "You CAN'T DO THAT!" And I will say, "Yes I
know that you WON'T DO THAT" but I actually have done something
extremely similar which is likely to mean that I can do that.

Jan 3 '06 #9

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

Similar topics

6
3104
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from the table, but I was not allowed to do that, because "there are records related with those PRODUCTS in other tables (e.g. in table "ORDER_DETAIL").
3
1717
by: Vi | last post by:
Hi, I have a form which displays some orders based on dates selected or based on an order number. I have two different buttons for each kind of query, but both buttons call the same method in the code behind page. I'm validating the dates and if they're not ok, I set args.IsValid=false; In the method that retrieves the orders, I check if Page.IsValid. This way if the dates are not valid, the retrieval by dates is not working, but so is...
6
10680
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the data on the datasource. It simply gets the first name and last name of an instructor and displays it in the grid. I have two major problems.... One, it doesn't display in the column until the row is saved, (Even after calling a refresh on the...
13
3998
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate button "Unexpected Error":3251 operation is not supported for this type of object.The demo cd has two databases, one is called inventory and the other just has the tables for the design called inventory data. When you run inventory the database works...
1
1225
by: beavisny00 | last post by:
I have two tables (Orders) and (Products). Orders table has fields named: Order ID Product Name Catalog # Price Quantity Total Price Product table has fields named: Product ID
5
4848
by: SEEMO | last post by:
I am making a database for our factory, for managing production. I have a form for printing job orders(Job Prep) for each item to be produced, which user selects from a combo box, and the form contains a subform(Job Prep Sub), which lists the purchase orders for that item. Info comes from PO detail Query, which gets most of its info from PO detail table. I have a button on the form, on click, prints current record. The problem Im having is,...
3
2267
by: emgallagher | last post by:
I have a form which lists studies. People can filter the form based on details about the study, such as the study type. Currently users filter via the right click method. I would like to be able to have a report that shows just the filtered records. The code that I tried which didn't work:
4
2749
by: awcem | last post by:
I am working with Microsoft access 2003 i have a continuous form which shows summary date for purchase orders. This form is based on a query which looks at the Purchase Orders table and the Purchase Orders detail table One of the fields in this contiuous form is the Order ID. When a user clicks on the order ID, i want them to see the full details for that order ID, based onthe "purchaseOrdersView" form I have the following code Private Sub...
3
10881
by: MyWaterloo | last post by:
I am trying to open my purchase orders form and go to the last record. In the on open command I do: DoCmd.GoToRecord , , acLast Seems straight forward enough...but I keep getting this message "You entered an expression that has invalid reference to the property Form/Report" before the form opens. After I acknowledge the message the form opens and goes to the last record. How do I X the message.
0
9589
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
9423
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
9997
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
9865
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
8873
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.