Hello all,
Trying to make a userform enter data in a log but I need to force the user to fill out all information or it will not enter data into the table. Below is the code I have presently:
A simple test is to just click the submit button. It does tell you to complete the form, but enters a blank line (besides the formulated columns that include on the table). Any pointers would be greatly appreciated.
Trying to make a userform enter data in a log but I need to force the user to fill out all information or it will not enter data into the table. Below is the code I have presently:
Code:
Private Sub CommandButton_Add_Click()
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("2019")
Set table_list_object = the_sheet.ListObjects(1)
Set table_object_row = table_list_object.ListRows.Add
'check for a Name number
If Trim(Me.TextBox_Time.Value) = "" Then
Me.TextBox_Time.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
table_object_row.Range(1, 1).Value = Date
table_object_row.Range(1, 2).Value = Me.TextBox_Time.Value
table_object_row.Range(1, 3).Value = Me.TextBox_Order.Value
table_object_row.Range(1, 4).Value = Me.ComboBox_Venue.Value
table_object_row.Range(1, 6).Value = Me.TextBox_Driver.Value
table_object_row.Range(1, 7).Value = Me.ListBox_Problem.Value
table_object_row.Range(1, 8).Value = Me.TextBox_Hours.Value
table_object_row.Range(1, 10).Value = Me.TextBox_Detail.Value
'check for a Name number
If Trim(Me.TextBox_Time.Value) = "" Then
Me.TextBox_Time.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
MsgBox "Transportation Issue Added", vbOKOnly + vbInformation, "Transportation Issue Added"
'clear the data
Me.TextBox_Time.Value = ""
Me.TextBox_Order.Value = ""
Me.ComboBox_Venue.Value = ""
Me.TextBox_Driver.Value = ""
Me.ListBox_Problem.Value = ""
Me.TextBox_Hours.Value = ""
Me.TextBox_Detail.Value = ""
Me.TextBox_Time.SetFocus
End Sub
Private Sub CommandButton_Close_Click()
Unload Me
End Sub
A simple test is to just click the submit button. It does tell you to complete the form, but enters a blank line (besides the formulated columns that include on the table). Any pointers would be greatly appreciated.