I have a userform that I am trying to get working. I have the inputs all set, make the validation, set it if correct but can't seem to get past the 'copy the data to the data base'. Here is my code:
Any help on why I am getting this error would be greatly appreciated. Thank you VBA wizards!
Code:
Private Sub CommandButton_Add_Click()
'----------------------------------------------------
'declare objects
'----------------------------------------------------
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
'----------------------------------------------------
'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 Validation of Completed form
'----------------------------------------------------
If Trim(Me.TextBox_Time.Value) = "" Then
Me.TextBox_Time.SetFocus
MsgBox "Please fill in Time on form"
Exit Sub
End If
If Trim(Me.TextBox_Order.Text) = "" Then
Me.TextBox_Order.SetFocus
MsgBox "Please fill in 'Order #' on form"
Exit Sub
End If
If Trim(Me.ComboBox_Venue.Value) = "" Then
Me.ComboBox_Venue.SetFocus
MsgBox "Please fill in 'Venue Location #' on form"
Exit Sub
End If
If Trim(Me.TextBox_Driver.Value) = "" Then
Me.TextBox_Driver.SetFocus
MsgBox "Please fill in 'Driver' on form"
Exit Sub
End If
If Trim(Me.ListBox_Problem.Value) = "" Then
Me.ListBox_Problem.SetFocus
MsgBox "Please fill in 'Problem Category' on form"
Exit Sub
End If
If Trim(Me.TextBox_Hours.Value) = "" Then
Me.TextBox_Hours.SetFocus
MsgBox "Please fill in 'Hours Impact' on form"
Exit Sub
End If
If Trim(Me.TextBox_Detail.Value) = "" Then
Me.TextBox_Detail.SetFocus
MsgBox "Please fill in 'Problem Detail' on form"
Exit Sub
End If
'------------------------------------------------------
'Set objects in worksheet
'------------------------------------------------------
Set the_sheet = Sheets("2019")
Set table_list_object = the_sheet.ListObjects(1)
Set table_object_row = table_list_object.ListRows.Add
'------------------------------------------------------
'Message box when data has been correctly added
'------------------------------------------------------
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
Any help on why I am getting this error would be greatly appreciated. Thank you VBA wizards!