Aretradeser
Board Regular
- Joined
- Jan 16, 2013
- Messages
- 176
- Office Version
- 2013
- Platform
- Windows
Exception to the obligation to fill in all fields of a UserForm
Through a UserForm I have a form with which I register a series of data. In principle, this code requires all the fields to be filled in, if they are not filled in then the empty ComboBox and Textbox are coloured in red and you get a warning screen, which warns you: "DATA NOT FILLED IN", preventing you from registering the data, as all the fields are not filled in.
The problem is that I don't know how to modify this code to make an exception with one of the ComboBoxes, specifically with the ComboBox2. I want that, although this ComboBox2 is not filled in, the rest of the data can be registered.
CODE
Through a UserForm I have a form with which I register a series of data. In principle, this code requires all the fields to be filled in, if they are not filled in then the empty ComboBox and Textbox are coloured in red and you get a warning screen, which warns you: "DATA NOT FILLED IN", preventing you from registering the data, as all the fields are not filled in.
The problem is that I don't know how to modify this code to make an exception with one of the ComboBoxes, specifically with the ComboBox2. I want that, although this ComboBox2 is not filled in, the rest of the data can be registered.
CODE
Rich (BB code):
Private Sub cmdbRegistrar_Click()
Dim Salir As Boolean
Dim fe1 As Date
Dim fe2 As Date
Dim NotComplete As Boolean
Dim i As Integer, a As Integer
For i = 1 To 7
For a = 1 To 2
With Me.Controls(Choose(a, "ComboBox", "TextBox") & i)
If .Enabled Then .BackColor = IIf(Len(.Text) > 0, vbWindowBackground, vbRed)
If .BackColor = vbRed Then NotComplete = True
End With
Next a
Next i
If NotComplete Then
MsgBox "DATA NOT FILLED IN !!!", vbExclamation, "Entry Required"
Exit Sub
End If
If IsDate(TextBox1) Then fe1 = CDate(TextBox1)
fe1 = CDate(TextBox1)
TextBox1 = Format(fe1, "mm/dd/yyyy")
If Not IsDate(TextBox2) Then
MsgBox "ENTER A VALID DATE", vbExclamation
TextBox2.SetFocus
Exit Sub
End If
fe2 = CDate(TextBox2)
TextBox2 = Format(fe2, "mm/dd/yyyy")
Sheets("BDATOS").Select
Sheets("BDATOS").Unprotect ("123")
With Worksheets("BDATOS")
t = Cells(Rows.Count, 2).End(xlUp).Row
If Me.ComboBox1 = "ESPAÑA" Or Me.ComboBox1 = "PORTUGAL" Then
Cells(t + 1, 2) = TextBox6 & " " & Trim(TextBox7) & ", " & TextBox5
Else
Cells(t + 1, 2) = Trim(TextBox6) & ", " & TextBox5
End If
Cells(t + 1, 3) = ComboBox5
Cells(t + 1, 4) = ComboBox6
Cells(t + 1, 5) = ComboBox1
Cells(t + 1, 6) = ComboBox2
Cells(t + 1, 7) = ComboBox3
Cells(t + 1, 8) = ComboBox4
Cells(t + 1, 9) = TextBox1.Value
Cells(t + 1, 10) = TextBox2.Value
Cells(t + 1, 11) = 0 + TextBox3
Cells(t + 1, 12) = ComboBox7
Cells(t + 1, 13) = TextBox4.Value
Cells(t + 1, 14) = Right(TextBox1.Value, 4)
End With
Cells(t, 13).Select
Selection.AutoFill Destination:=Range("M" & t & ":M" & t + 1), Type:=xlFillDefault
Sheets("BDATOS").Protect ("123")
For n = 1 To 12
On Error Resume Next
Controls("textbox" & n) = ""
Controls("combobox" & n) = ""
Next
Sheets("DATOS").Select
Cells.Select
Cells.EntireColumn.AutoFit
End Sub