event after clicking 'ok' for pop-up msgbox that appears(?)

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
458
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I googled this, but could not find an answer that fit the criteria of my code/event... so here is my problem:

I have a simple procedure that after a user tries to close out a userform (via a command button), if certain checkboxes are NOT 'ticked' then it gives them a simple warning box along with changing the color to yellow for the choice of boxes where one of them must be selected:

Capture.PNG


My code:
VBA Code:
' Only allow selection of Hourly Check Box -OR- Salary Check Box, but not BOTH (turn both boxes YELLOW if neither are selected)
If Me.chkHourly = False And Me.chkSalary = False Then
Me.chkSalary.SetFocus
Me.chkSalary.BackColor = &HFFFF&
Me.lblSalary.BackColor = &HFFFF&
Me.lblHourly.BackColor = &HFFFF&
Me.chkHourly.BackColor = &HFFFF&
MsgBox "You must Select either Hourly or Salary"
Exit Sub
End If


After googling, I read where after the MsgBox 'ok' is clicked the very next line of code in the module will be ran next, but, no matter where I put the code to put the color back to the original userform color, it doesn't follow/perform it.

After hitting 'ok' I simply need the boxes/labels to revert back to this:
Capture1.PNG


so this does not give the effect I am looking for:

VBA Code:
' Only allow selection of Hourly Check Box -OR- Salary Check Box, but not BOTH (turn both boxes YELLOW if neither are selected)
If Me.chkHourly = False And Me.chkSalary = False Then
Me.chkSalary.SetFocus
Me.chkSalary.BackColor = &HFFFF&
Me.lblSalary.BackColor = &HFFFF&
Me.lblHourly.BackColor = &HFFFF&
Me.chkHourly.BackColor = &HFFFF&
MsgBox "You must Select either Hourly or Salary"
' recolor the backcolor of the labels/checkboxes back to the userform template color after user hits 'ok' for the msgbox:
Me.chkSalary.BackColor = &HC8DAC6
Me.lblSalary.BackColor = &HC8DAC6
Me.lblHourly.BackColor = &HC8DAC6
Me.chkHourly.BackColor = &HC8DAC6
Exit Sub
End If
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
As an alternative suggestion, how about clearing the warning backcolor when user selects one of the checkboxes?

VBA Code:
Private Sub chkHourly_Click()
    WarningBackColor False
End Sub

Private Sub chkSalary_Click()
    WarningBackColor False
End Sub

Sub WarningBackColor(ByVal State As Boolean)
    Const Warningcolor As Long = &HFFFF&
    Const NormalColor As Long = &HC8DAC6
    
    chkSalary.BackColor = IIf(State, Warningcolor, NormalColor)
    Me.lblSalary.BackColor = IIf(State, Warningcolor, NormalColor)
    Me.lblHourly.BackColor = IIf(State, Warningcolor, NormalColor)
    Me.chkHourly.BackColor = IIf(State, Warningcolor, NormalColor)
End Sub

and your code to check status

VBA Code:
If Me.chkHourly = False And Me.chkSalary = False Then
        WarningBackColor True
        MsgBox "You must Select either Hourly or Salary", 48, "Selection Required"
    End If

Dave
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top