This is for the reference code for the simple form which i have.
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub ResetComboBox_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
Private Sub SubmitComboBox_Click()
If Me.DestinationComboBox.Value = "" Then
MsgBox "Please choose a destination.", vbExclamation, "Travel Destination"
Me.DestinationComboBox.SetFocus
Exit Sub
End If
If Me.DateTextBox.Value = "" Then
MsgBox "Please select a date.", vbExclamation, "Travel Date"
Me.DateTextBox.SetFocus
Exit Sub
End If
If Not IsDate(Me.DateTextBox.Value) Then
MsgBox "The Date field must contain a date.", vbExclamation, "Travel Date"
Me.DateTextBox.SetFocus
Exit Sub
End If
If Me.BudgetTextBox.Value = "" Then
MsgBox "Please insert your budget.", vbExclamation, "Travel Budget"
Me.BudgetTextBox.SetFocus
Exit Sub
End If
If Not IsNumeric(Me.BudgetTextBox.Value) Then
MsgBox "The budget field must contain number.", vbExclamation, "Travel Budget"
Me.BudgetTextBox.SetFocus
Exit Sub
End If
Dim RowCount As Long
RowCount = Worksheets("Parameters").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Parameters").Range("A1")
.Offset(RowCount, 0).Value = Me.DestinationComboBox.Value
.Offset(RowCount, 1).Value = Me.DateTextBox.Value
.Offset(RowCount, 2).Value = DateValue(Me.DateTextBox.Value)
.Offset(RowCount, 3).Value = Me.BudgetTextBox.Value
.Offset(RowCount, 4).Value = Me.BudgetTextBox.Value
.Offset(RowCount, 5).Value = Format(Now, "dd/mm/yyyy hh:nn:ss")
End With
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub