If part doesnt already appear Append otherwise Update

D

DawnTreader

Hello All

i have a form where i have a "shopping cart" that the user has 2 buttons
that cause a quantity of parts to be added to an order. each time they hit
the + button it needs to add a qty of 1 to the table. if there is already 1
of that part in the table it needs to update the table so that there is now 1
more to the current qty, and if the part isnt in the table then it needs to
add the part and give it a qty of 1. the - button on the form is intended to
do the reverse.

currently this is all done directly to the part order line item table, the
problem is that each subsequent hit of the + button adds a new line item, it
isnt looking for the part id to see if it is already there. the other problem
is that the - button doesnt just remove a qty of 1, it wipes out all of the
items in the table.

i am thinking that a temporary table would be a better set up. my idea is to
add all the parts to a table and then when the user hits the "add to cart"
button, an update / append query will add the parts to the proper part order
table. the problem is that i am unsure i can get one query that does both the
append and updating of records. do i need to break this into 2 operations?
is there any examples out there that might help me figure this out?

all and any help is appreciated! :)
 
P

Paul Shapiro

You could write code for the form's BeforeUpdate event. In your code, if the
current record is a new record (being added to the table), check to see if
the part number already exists in the order item table with the same order
number. If so, update the existing quantity, cancel the insert, and requery
the form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top