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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

undoing a change in a combo box

Status
Not open for further replies.

misterhux

Programmer
Aug 27, 2003
36
US
So I have a couple of combo boxes in my form, that when they change they need to invalidate data. So when they they change, before they do change they need to ask the user if they are sure they want to change the combo boxes. My problem is that I can't get the combo_box.undo to work, and when I look at the combo_box.oldValue, it is the same as the current value. (I'm doing all the code in the combo_box_beforeUpdate, I also tried it in the Change event too.). Any thoughts on to why the values are staying the same, (or rather that they are updating before the beforeUpdate event.)

thanks
 
When they click on the combo box it will fire an event
the events are listed in the properties of the combo box.
Open the properties and click the “Event” TAB at the top
If you choose one of these to store the value then you will have it later.
If you display a message in the after update event you have the old value stored and can put it back if they answer no.


Private Sub YourCombo_AfterUpdate()
Dim retval As Variant
retval = MsgBox("Are you sure you eant to change", vbExclamation + vbYesNo, "Title goes here")
If retval = vbNo Then
Me!YourCombo = OldValue
End If
End Sub

Private Sub YourCombo_BeforeUpdate(Cancel As Integer)
'note you have to add Global OldValue in a Module
OldValue = Me!YourCombo
End Sub


DougP, MCP
 
thanks for your help, but it doesn't seem to work, I tried that and got error #2115, saying that Access wont let the field be updated, or something in that respect
 
I'm not sure if you ever got your answer, but this worked for me.

Private Sub cboCompany_BeforeUpdate(Cancel As Integer)

If IsNull(Me.cboCompany) Then
If MsgBox("Delete Address", vbYesNo) = vbYes Then
'Delete Address
Else
Cancel = True
Me.cboCompany.Undo
End If
End If

End Sub

Hope this helps.

Rene'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top