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

How do I halt code if combo box value not changed?

Status
Not open for further replies.

djayam

Technical User
Aug 16, 2005
95
GB
Hi guys,

I have a combo box where users choose an order type. Their selection will determine the visibility of subforms.
Code:
Private Sub Combo_OrderType_Change()

If Me.Combo_OrderType = 1 Then Me.frm_OrderPart_Purchase.Visible = True Else Me.frm_OrderPart_Purchase.Visible = False
Me.frm_OrderPart_Purchase.Requery

End Sub
What I want to do is if the value doesn't change to skip this (like pressing the escape key). I tried using .oldvalue -
Code:
'If Me.Combo_OrderType.Value = Me.Combo_OrderType.OldValue Then GoTo NoChange
If Me.Combo_OrderType = 1 Then Me.frm_OrderPart_Purchase.Visible = True Else Me.frm_OrderPart_Purchase.Visible = False
Me.frm_OrderPart_Purchase.Requery

NoChange:
End Sub
But no joy. Any ideas?

Thanks loads,

Jason
 
The Change event gets fired every single time a character changes (gets added or deleted) in the combobox.

If you move the code (and change the event to) AfterUpdate, then it will only get triggered after an update is successful.
You therefore will have guaranteed that data will have changed in there.

John
 
Thanks, I wrote a workaround using an invisible control but I'll try this later.

Thanks again.
 
. . . or you can use the [blue]BeforeUpdate[/blue] event where the [blue]Old Value[/blue] is still preserved:
Code:
[blue]   Dim CBx As ComboBox, OP As Control, flg As Boolean
   
   Set CBx = Me.Combo_OrderType
   Set OPP = Me.frm_OrderPart_Purchase
   
   If CBx <> CBx.OldValue Then
      If CBx = 1 Then flg = True
      OP.Visible = flg
      OP.Requery
   Else
      [purple][b]Cancel = True[/b][/purple]
   End If
   
   Set OP = Nothing
   Set CBx = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top