Search code examples
excelvbauserformmsgbox

How can I make a msgbox appear on a Userform when the person enters a specific value


I have created a userform in Excel which will populate a database. However, there is a combobox in my userform where the user selects a specific rate from a list of three. When one specific rate is selected, I need to show an error message immediately. I have other error messages that will show when the user selects to 'Submit' the form, but I need this one to populate as soon as the value is selected. I have corrected my other coding issue so this should not be related to that.

The code that I have so far is here:

Private Sub cmbMileageRates_Change()

    If cmbMileageRates.Value = ".58" Then
        MsgBox "When requesting mileage reimbursement of the high rate($.58/mile), Division Administrator Approval is required", 0, "Critical"
        Exit Sub
    End If

End Sub

Solution

  • Why don't you use event "cmbMileageReimbRates_change"?

    Private Sub cmbMileageReimbRates_Change()
    If cmbMileageReimbRates.Value = ".58" Then
        MsgBox "When requesting mileage reimbursment of the high rate ($.58/mile), Division 
         Administrator Approval is required", vbCritical
        Exit Sub
    End If
    End Sub