Help with AfterUpdate combobox (1 Viewer)

gojets1721

Registered User.
Local time
Today, 07:21
Joined
Jun 11, 2019
Messages
430
I have a combobox with three preset values (New, In Progress, Closed).

I want to have VBA where if the combobox's value is changed from 'Closed' to 'In Progress', then my date field (ClosedDate) is changed to null.

Any suggestions? I don't know how to specifically make an action happened when one specific value is changed to another (i.e. I want nothing to happen if the combobox is changed from 'New' to 'In Progress').
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:21
Joined
Feb 28, 2001
Messages
27,223
You need to write event code for the Combo Box change event.


Inside the the combo's change event, you can compare the combo's .OldValue to its .Value and decide if the specific transition just occurred. If not a change from Closed to InProgress, do nothing.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:21
Joined
Feb 19, 2002
Messages
43,352
I would put the code in the Form's BeforeUpdate event. That way you won't have to handle multiple changes to the field and trying to figure out if you need to bring back the date you just removed. The Form's BeforeUpdate event is the last event that runs before the record gets saved so the user won't have an opportunity to waffle:)
 

gojets1721

Registered User.
Local time
Today, 07:21
Joined
Jun 11, 2019
Messages
430
I would put the code in the Form's BeforeUpdate event. That way you won't have to handle multiple changes to the field and trying to figure out if you need to bring back the date you just removed. The Form's BeforeUpdate event is the last event that runs before the record gets saved so the user won't have an opportunity to waffle:)
Okay thanks. So I tried the below code in the BeforeUpdate. It's still changing it to 'In progress' even if I select 'no' from the msgbox. It seems like it's not voiding the user's change to the combobox. Do I need to code it to do that?

Code:
    Dim strResponse As String
 
    DoCmd.SetWarnings False

    If Me.comboComplaintStatus.OldValue = "Closed" And Me.comboComplaintStatus.Value = "In progress" Then
         
        strResponse = MsgBox("This complaint is closed. Are you sure you want to re-open it?", vbYesNo, ApplicationName)
             
        If strResponse = vbYes Then
                 
            Me.comboComplaintStatus = "In progress"
            Me.txtClosedDate = ""
               
        Else
            'do nothing
        End If
     
    End If
 

cheekybuddha

AWF VIP
Local time
Today, 15:21
Joined
Jul 21, 2014
Messages
2,288
It's still changing it to 'In progress' even if I select 'no' from the msgbox. It seems like it's not voiding the user's change to the combobox. Do I need to code it to do that?
Yes, you must add Cancel = True within that section of the If block.
 

cheekybuddha

AWF VIP
Local time
Today, 15:21
Joined
Jul 21, 2014
Messages
2,288
No, before the 'Else'

Sorry, just re-read your code.

Yes, after the 'Else'

😬
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:21
Joined
Feb 19, 2002
Messages
43,352
You might find the videos here helpful
 

Users who are viewing this thread

Top Bottom