oldvalue, combo box, beforeupdate

F

franc sutherland

Hello everyone,

I am using Access 2003.

In a sales order form, the customer is selected used a combo box for
which the bound column is the customer_id field, which is the
autonumber key in the customers table.

When someone goes back in to the sales order and changes the customer
for that order, I want to pop up a message box which will ask them to
confirm the change. If they say no, I want the record to return to
the initial value. If they say, yes, the customer_id will change and
the other fields populated with the new information. The lookup is
carried out in the AfterUpdate event using Dlookup.

In the BeforeUpdate event, I see if the new customer_id is the same as
the oldvalue customer_id and if it is, that's no change. If there is
a difference, I then ask them to confirm if they want that change
using a message box with vbyesno. Probably best to paste in the code
at this point!

--

Select Case new_id

Case Is = old_id

MsgBox "no change"

Case Else

customer_change = MsgBox("Do you want to change customer?",
vbYesNo)

Select Case customer_change

Case Is = vbNo

Me.customer_id.Undo

Cancel = True

Case Else

Cancel = False

End Select


End Select

Debug.Print Me.customer_id

End Sub

--

This method works to determine whether they want to change the
customer or not. The undo reverts the value in the combo box back to
the oldvalue, however the debug.print shows that the customer_id is
not changed.

If customer 1 is the original data and I change it to customer 2, then
I select yes in the message box, it works fine. If I select No from
the message box, the value shown in the combo box is correct, but the
me.customer_id value printed by debug gives the customer_id of
customer 2.

I tried putting in the line of me.customer_id = old_id, but this gave
the 2115 error.

Thanks in advance,

Franc.
 
K

Ken Snell \(MVP\)

Until the BeforeUpdate event finishes, it will see the newly entered value
for the combobox. After the event is finished, it'll see the value that
remains in the combo box. So there is no problem with the code other than
your desire to print the value in the Debug.Print statement. Why do you need
that value to print? Are you just testing to be sure that the code works the
way you want?
 

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