Rahul Gupta
Rahul Gupta

Reputation: 1802

update textbox depending upon combo box values

I have a combo box having 4 values
Level 1
Level 2
Level 3
Level 4
I want to update my text box to current date whenever user changes the value in combo box.
What I am struggling with the following scenario
Suppose user changes the value of combo box from Level 1 to Level 2, text box is updated to current date. No issues
In the same session, same user changes the combo box value from level 2 to level 1, then text box should be updated to old date for level 1.
I am using continuous form
Any help is appreciated.

Upvotes: 0

Views: 1489

Answers (1)

PaulFrancis
PaulFrancis

Reputation: 5819

This could be a litte bit tricky to understand. I will try my best to explain it properly. The event you are currently using would be the ComboBox After update. This could be a lot more easier to handle if you moved the code into the Form Before update, alongside with the AfterUpdate of the ComboBox. This will bring the session under one roof.

What I mean is in the BeforeUpdate event, first check if the value of the ComboBox has changed. If it has, then change the value of the Datecontrol.

Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.comboBoxName.OldValue = Me.comboBoxName.Value Then
        Me.dateControlName.Undo
    End If
End Sub

For this to work the ComboBox should be bound to a field in the table.

Upvotes: 2

Related Questions