MsgBox advice for two different message options

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning.
I am using the code supplied below.
The issue i believe is with the code in Red.
The message concenred is in BLUE

This is used on a userform where making a selection from a ComboBox would then show two different selectable options BUT the message shown in BLUE below in shown for BOTH & ideally would like two different messages.

Example

If i select "TEST 1" from the ComboBox & i then see OptionButton1 & OptionButton3 appear.
If i now dont select either & try to continue i see the message shown in RED below.

If i select "TEST 2" from the ComboBox & i then see OptionButton2 & OptionButton4 appear.
If i now dont select either & try to continue i see the message shown in RED below.

So the same message shown for both cases, Ideally would be nice to see message YOU DID NOT SELECT EITHER OPTION 1 OR 3 & another message like YOU DID NOT SELECT EITHER OPTION 2 OR 4
So each have there own message
Rich (BB code):
Private Sub TransferButton_Click()
With ThisWorkbook.Worksheets("RANGER")
    Dim i As Long
    Dim x As Long
    Dim ctrl As Control
    Dim lastrow As Long

    Cancel = 0
    If TextBox1.Text = "" Then
        Cancel = 1
        MsgBox "NO CUSTOMER'S NAME WAS ENTERED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
        TextBox1.SetFocus

    ElseIf TextBox2.Text = "" Then
        Cancel = 1
        MsgBox "YOU DIDNT ENTER THE VIN", vbCritical, "RANGER FIELD EMPTY MESSAGE"
        TextBox2.SetFocus

    ElseIf ComboBox1.Text = "" Then
        Cancel = 1
        MsgBox "NO YEAR WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
        ComboBox1.SetFocus

    ElseIf ComboBox2.Text = "" Then
        Cancel = 1
        MsgBox "REMOTE TYPE WAS NOT SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
        ComboBox2.SetFocus
    End If

    If Cancel = 1 Then
        Exit Sub
    End If
    
    x = 0
    For i = 1 To 4
     If Me.Controls("OptionButton" & i) = True Then
     x = x + 1
     Opt = i
     End If
     
    Next
    If x = 0 Then
        MsgBox "YOU DIDNT SELECT AN OPTION BUTTON", vbCritical, "RANGER OPTION BUTTON EMPTY MESSAGE"
        Exit Sub
    End If

    Rows("5:5").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("B5:I5").Borders.LineStyle = xlContinuous
    Range("B5:I5").Borders.Weight = xlThin
    Range("B5:I5").Interior.ColorIndex = 6
    Range("C5:I5").HorizontalAlignment = xlCenter
    Sheets("RANGER").Range("B5").Select
    Cancel = 0
    
    If Cancel = 1 Then
        Exit Sub
        
    End If
    With ThisWorkbook.Worksheets("RANGER")
        .Range("B5").Value = TextBox1.Text
        .Range("D5").Value = TextBox2.Text
        .Range("F5").Value = TextBox3.Text
        .Range("G5").Value = TextBox4.Text
        .Range("C5").Value = ComboBox1.Text
        .Range("H5").Value = ComboBox2.Text
        .Range("E5").Value = Me.Controls("OptionButton" & Opt).Caption
    End With
        
    If ComboBox2.Value = "ORIGINAL 2B" Then

 Unload RangerFormRemote
 RangerPcbNumber.Show
    
 Else
    With .Range("I5")
        .Value = "N/A"
        .Font.Size = 14
        .Font.Name = "Calibri"
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlVAlignCenter
        Unload RangerFormRemote
     End With

    With Sheets("RANGER")
        If .AutoFilterMode Then .AutoFilterMode = False
        x = .Cells(.Rows.Count, 5).End(xlUp).Row
        .Range("A4:I" & x).Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlGuess
        MsgBox "DATABASE UPDATED SUCCESSFULLY", vbInformation, "SUCCESSFUL MESSAGE"
    End With
        Application.ScreenUpdating = True
    Range("B6").Select
    Range("B5").Select
    End If
 End With
 
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Here is my update

Ive added the code in green to follow suit for the code above it BUT i dont select either OptionButton 2 or 4 BUT still see the msg for the above code and not the msg for the optionbutton mentioned here.

What am i doing wrong ?


Rich (BB code):
Private Sub TransferButton_Click()
With ThisWorkbook.Worksheets("RANGER")
    Dim i As Long
    Dim x As Long
    Dim ctrl As Control
    Dim lastrow As Long

    Cancel = 0
    If TextBox1.Text = "" Then
    Cancel = 1
        MsgBox "NO CUSTOMER'S NAME WAS ENTERED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
        TextBox1.SetFocus

    ElseIf TextBox2.Text = "" Then
    Cancel = 1
        MsgBox "YOU DIDNT ENTER THE VIN", vbCritical, "RANGER FIELD EMPTY MESSAGE"
        TextBox2.SetFocus

    ElseIf ComboBox1.Text = "" Then
    Cancel = 1
        MsgBox "NO YEAR WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
        ComboBox1.SetFocus

    ElseIf ComboBox2.Text = "" Then
    Cancel = 1
        MsgBox "REMOTE TYPE WAS NOT SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
        ComboBox2.SetFocus
    
    ElseIf OptionButton5.Value = False And OptionButton6.Value = False Then
    Cancel = 1
        MsgBox "NO FINIS NUMBER WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
        
    ElseIf OptionButton2.Value = False And OptionButton4.Value = False Then
    Cancel = 1
        MsgBox "NO UPRATED OPTION WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
    End If
    
    If Cancel = 1 Then
        Exit Sub
    End If
 
Upvote 0
I guess that's just because VBA codes run top-down?
Try moving the lines in green to the topmost in the IF statement.
 
Upvote 0
Hi,
That made no difference.

So see this below as these are the two which cause the issue
Remember both have a different message.
With both in use i see the same message appear.

My test was to remove the code in RED & only have the BLUE code
The message i then see is correct NO UPRATED WAS SELECTED.

I then did opposite.
Remove the BLUE code & only have the RED code
The message i then see is correct NO FINIS WAS SELECTED

So the code will not work if both in use.

I put both in frames BUT made no difference unless i did something wrong.

I then changed OptionButtons for CheckBox with & without frames but also made no difference unless i did something wrong.



Rich (BB code):
    ElseIf OptionButton5.Value = False And OptionButton6.Value = False Then
    Cancel = 1
MsgBox "NO FINIS NUMBER WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
       
 ElseIf OptionButton2.Value = False And OptionButton4.Value = False Then
    Cancel = 1
MsgBox "NO UPRATED OPTION WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
    End If
 
Upvote 0
With the code in #4, if OptionButton5, 6, 2, and 4 are all unchecked then the message "NO FINIS NUMBER WAS SELECTED" should show up because that's how you write the code.
Do you mean you need the message "NO UPRATED OPTION WAS SELECTED" when all of those are unchecked?
If so, just flip the order of the lines in red and blue.
In any way, the code doesn't run the way you want it to because you haven't written the conditions so that it runs the way you want it to, as far as I can imagine.
 
Upvote 0
No,

If OptionButton5 OR OptionButton6 is not selected show NO FINIS NUMBER WAS SELECTED

If OptionButton2 OR OptionButton4 is not selected show NO UPRATED OPTION WAS SELECTED
 
Upvote 0
That makes no difference and does the same,i think its a bit more involved that just change these words
 
Upvote 0
Rich (BB code):
    ElseIf OptionButton5.Value = False Or OptionButton6.Value = False Then
        Cancel = 1
        MsgBox "NO FINIS NUMBER WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"      
     ElseIf OptionButton2.Value = False Or OptionButton4.Value = False Then
        Cancel = 1
        MsgBox "NO UPRATED OPTION WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
    End If
With this, if OptionButton5 and OptionButton6 are BOTH checked BUT either of OptionButton2 or OptionButton4 is unchecked, you should see "NO UPRATED OPTION WAS SELECTED".
If this isn't the way you want the code to work, you'll need to add other conditions.
 
Upvote 0
No its like this.

OptionButton5 or OptionButton6 is the only option and user MUST select one of them

If neither is selected then show NO FINIS NUMBER WAS SELECTED

IT IS NOT POSSIBLE TO SELECT BOTH

ALSO

OptionButton2 or OptionButton4 is the only option and user MUST select one of them

If neither is selected then show NO UPRATED OPTION WAS SELECTED

IT IS NOT POSSIBLE TO SELECT BOTH
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,746
Members
449,050
Latest member
excelknuckles

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