Open specific form when ComboBox & Textbox values are checked first

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,859
Office Version
  1. 2007
Platform
  1. Windows
Please can you advise the following edit i need to make.
Currently my code in use opens a form where it looks at ComboBox2 value & if the value is ORIGINAL 2B it opens the form RangerPcb

This is where i need that to be changed.
I would like it to also look at another value & then open the correct form.

It should work like this but obviously written correctly.

If ComboBox2.Value = "ORIGINAL 2B" & TextBox3.Value = "41835" Then
RangerPcb41835.Show
Else
If ComboBox2.Value = "ORIGINAL 2B" & TextBox3.Value = "41601" Then
RangerPcb41601.Show

Thanks

VBA Code:
        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

        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"
            .Range("B5").Select
        End If

    End With
    
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Like so
VBA Code:
If ComboBox2.Value = "ORIGINAL 2B" And TextBox3.Value = "41835" Then
    RangerPcb41835.Show
ElseIf ComboBox2.Value = "ORIGINAL 2B" And TextBox3.Value = "41601" Then
    RangerPcb41601.Show
Else
    ' do nothing ?
End If
 
Upvote 0
That didnt open the form in question at all.
Full code shown.


Rich (BB code):
Private Sub TransferButton_Click()
    Dim i As Long, x As Long

    With Sheets("RANGER")

        If TextBox1.Value = "" Then
            MsgBox "NO CUSTOMER'S NAME WAS ENTERED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            TextBox1.SetFocus
            Exit Sub
        ElseIf TextBox2.Value = "" Then
            MsgBox "YOU DIDNT ENTER THE VIN", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            TextBox2.SetFocus
            Exit Sub
        ElseIf ComboBox1.Value = "" Then
            MsgBox "NO YEAR WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            ComboBox1.SetFocus
            Exit Sub
        ElseIf ComboBox2.Value = "" Then
            MsgBox "REMOTE TYPE WAS NOT SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            ComboBox2.SetFocus
            Exit Sub
        ElseIf OptionButton5.Value = False And OptionButton6.Value = False And OptionButton5.Visible = True And OptionButton6.Visible = True Then
            MsgBox "NO FINIS NUMBER WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            Exit Sub
        ElseIf OptionButton2.Value = False And OptionButton4.Value = False And OptionButton2.Visible = True And OptionButton4.Visible = True Then
            MsgBox "NO UPRATED OPTION WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            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

        .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
       
        If ComboBox2.Value = "ORIGINAL 2B" Then
            Unload RangerFormRemote
        If ComboBox2.Value = "ORIGINAL 2B" And TextBox3.Value = "41835" Then
            RangerPcb41835.Show
        ElseIf ComboBox2.Value = "ORIGINAL 2B" And TextBox3.Value = "41601" Then
            RangerPcb41601.Show
        Else

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

        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"
            .Range("B5").Select
        End If

    End With
    
End Sub
 
Upvote 0
Remark: Unless you modify the ComboBox2.Value during the RangerFormRemote Unload, there is no point in checking the value again, you did it 1 row before.

However, it should not pose a problem. My assumption is that TextBox3.Value is different from the ones specified in your code. Did you take the time to run the code Row by Row with F8 and/or to put a breakpoint on row

VBA Code:
.Range("E5").Value = Me.Controls("OptionButton" & Opt).Caption

You'd see the problem immediately. What i can see however is very limited.
 
Upvote 0

Forum statistics

Threads
1,225,745
Messages
6,186,788
Members
453,371
Latest member
HMX180

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