Aretradeser
Board Regular
- Joined
- Jan 16, 2013
- Messages
- 173
- Office Version
-
- 2013
- Platform
-
- Windows
I am trying to adapt the VBA code of a UserForm, with 3 ComboBoxes and 4 TextBoxes, to record data. At the moment, this code is giving me an error in the redmarked line. How can I solve it?
Rich (BB code):
Private Sub cmdbRegistrar_Click()
Dim Salir As Boolean
Dim fe1 As Date
Dim hora As Date
Dim NotComplete As Boolean
Dim i As Integer
For i = 1 To 7
With Me.Controls(Choose("ComboBox", "TextBox") & i)
If .Enabled Then .BackColor = IIf(Len(.Text) > 0, vbWindowBackground, vbRed)
If .BackColor = vbRed Then NotComplete = True
End With
Next i
If NotComplete Then
MsgBox "MISSING DATA TO BE FILLED IN !!!", vbExclamation, "Entry Required"
Exit Sub
End If
If IsDate(TextBox2) Then fe1 = CDate(TextBox2)
fe1 = CDate(TextBox2)
TextBox2 = Format(fe1, "mm/dd/yyyy")
If Not IsDate(TextBox2) Then
MsgBox "PLEASE ENTER A VALID DATE", vbExclamation
TextBox3.SetFocus
Exit Sub
End If
hora = TimeValue((Time))
TextBox3 = Format(hora, "hh:mm")
Sheets("DATOS").Unprotect ("123")
With Worksheets("DATOS")
t = Cells(Rows.Count, 1).End(xlUp).Row
Cells(t, 1) = TextBox2.Value
Cells(t, 2) = TextBox3.Value
Cells(t, 5) = ComboBox2
Cells(t, 6) = ComboBox3
Cells(t, 7) = TextBox4.Value
Cells(t, 10) = TextBoxt.Value
Cells(t, 11) = ComboBox1
End With
Cells(t, 11).Select
Selection.AutoFill Destination:=Range("K" & t & ":K" & t + 1), Type:=xlFillDefault
Sheets("DATOS").Protect ("123")
For n = 1 To 7
On Error Resume Next
Controls("textbox" & n) = ""
Controls("combobox" & n) = ""
Next
Sheets("DATOS").Select
Cells.Select
Cells.EntireColumn.AutoFit
End Sub