Help with Run-time Error '91' with code

Status
Not open for further replies.

wmunsey81

New Member
Joined
Nov 30, 2017
Messages
29
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:

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!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top