ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Evening,
I am using the code shown below.
The problem is the code shown in Red.
I have a userform that i add a value or select it from a Combobox drop down list.
Using the command buttons the values are then transfered to the worksheet in columns B - H
I noticed that i could transfer the values even without making a selection for two combobox2 & comboBox3
So i added the code in Red to catch this & show the user a Msgbox etc etc.
Now when the code is run you must complete each option before it will transfer to the worksheet.
BUT the problem is that nothing is then entered into the cells in column F and H
Remove the code & it transfers perfect BUT no Msgbox is shown should you not make a selection from ComboBox 2 & ComboBox3
Do you see the error there ?
I am using the code shown below.
The problem is the code shown in Red.
I have a userform that i add a value or select it from a Combobox drop down list.
Using the command buttons the values are then transfered to the worksheet in columns B - H
I noticed that i could transfer the values even without making a selection for two combobox2 & comboBox3
So i added the code in Red to catch this & show the user a Msgbox etc etc.
Now when the code is run you must complete each option before it will transfer to the worksheet.
BUT the problem is that nothing is then entered into the cells in column F and H
Remove the code & it transfers perfect BUT no Msgbox is shown should you not make a selection from ComboBox 2 & ComboBox3
Do you see the error there ?
Rich (BB code):
Private Sub TransferButton_Click()
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 "CUSTOMER'S NAME FIELD IS EMPTY", vbCritical, "RANGER FIELD EMPTY MESSAGE"
TextBox1.SetFocus
ElseIf TextBox2.Text = "" Then
Cancel = 1
MsgBox "VIN FIELD IS NOT ENTERED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
TextBox2.SetFocus
ElseIf ComboBox1.Text = "" Then
Cancel = 1
MsgBox "YEAR IS NOT ENTERED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
ComboBox1.SetFocus
ElseIf ComboBox2.Text = "" Then
Cancel = 1
MsgBox "MAKE A SELECTION NOT SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
ComboBox2.SetFocus
ElseIf ComboBox3.Text = "" Then
Cancel = 1
MsgBox "FORD PART NUMBER NOT SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
ComboBox3.SetFocus
End If
If Cancel = 1 Then
Exit Sub
End If
Rows("5:5").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B5:H5").Borders.LineStyle = xlContinuous
Range("B5:H5").Borders.Weight = xlThin
Range("B5:H5").Interior.ColorIndex = 6
Range("C5:H5").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("E5").Value = "8C KEY"
.Range("G5").Value = "8C KEY"
.Range("C5").Value = ComboBox1.Text
.Range("H5").Value = ComboBox2.Text
.Range("F5").Value = ComboBox3.Text
End With
With Sheets("RANGER")
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.Count, 5).End(xlUp).Row
.Range("A4:H" & x).Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlGuess
End With
Unload RangerFormKey
ActiveWorkbook.Save
MsgBox "DATABASE HAS BEEN UPDATED", vbInformation, "SUCCESSFUL MESSAGE"
Application.ScreenUpdating = True
Range("B6").Select
Range("B5").Select
End Sub