Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with BeforeUpdate and AfterUpdate 2

Status
Not open for further replies.

marc2982

Programmer
Jun 29, 2006
5
CA
Hi guys,

I have a combo box named cboProjects. In it you can select either One or Two, with the corresponding IDs 1 and 2. The code I have is this:
Code:
Private Sub cboProjects_AfterUpdate()
   MsgBox "AfterUpdate: " & [cboProjects]
End Sub

Private Sub cboProjects_BeforeUpdate(Cancel As Integer)
   MsgBox "BeforeUpdate: " & [cboProjects]
End Sub
Now let's say One is chosen, and I go and select Two. From my understanding, I would expect it to display:
BeforeUpdate: 1
AfterUpdate: 2
However, this is not the case. This is what is displayed:
BeforeUpdate: 2
AfterUpdate: 2
which makes absolutely no sense!

Is it that my understanding is flawed, or am I not doing something right?

Thank you
Marc
 
Is it that my understanding is flawed...?
Yes. 'Before Update' is the value 'before the record is updated (written)' (i.e. before the database is updated) not 'before the form data changed'. Is that a little clearer?

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Before Update is before the data is written to the table, as I understand it, not before the control is changed. You can still cancel, and the combo will go back to OldValue (Me.cboProjects.OldValue).
 
Thanks for the response guys!

traingamer - That makes sense, now I know how it works!

Remou - I tried using cboProjects.OldValue, but it still gave me the new value, not the old one. Is there any way to do it without cancelling?

Thanks!
 
Is cboProjects bound to a control? If it is not, there is no OldValue.
 
OK I understand.

No, the combo box is unbound. I think I will try and fake it with a variable or hidden textbox or something.

Thanks again for the help. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top