Dim sort As Variant
Dim flagMuni As Boolean
Dim flagDecal As Boolean
Dim flagMat As Boolean
Dim wsI As Worksheet
Dim wsL As Worksheet
Set wsI = Worksheets("Incoming Sheet")
Set wsL = Worksheets("Lists")
'check municipality list
flagMuni = checkList("tblMunicipality", "Municipality", cmbMunicipality.Value)
'if municipality not recognized
If flagMuni = False Then
Dim responseMuni
responseMuni = MsgBox(cmbMunicipality.Value & " is not a recognized municipality, add to list?", vbYesNoCancel, "Confirmation")
If responseMuni = vbCancel Then Exit Sub
If responseMuni = vbYes Then
'if yes
Dim tableRowMuni As ListRow
Application.ScreenUpdating = False
Set tableRowMuni = wsL.ListObjects("tblMunicipality").ListRows.Add
tableRowMuni.Range(1, 1).Value = cmbMunicipality
'sort
sort = sortTable("Lists", "tblMunicipality", "Municipality", 1)
Application.ScreenUpdating = True
End If
End If
'check decal list
flagDecal = checkList("tblDecal", "Decal of Truck", cmbDecal.Value)
'if decal not recognized
If flagDecal = False Then
Dim responseDecal
responseDecal = MsgBox(cmbDecal.Value & " is not a recognized truck decal, add to list?", vbYesNoCancel, "Confirmation")
If responseDecal = vbCancel Then Exit Sub
If responseDecal = vbYes Then
'if yes
Dim tableRowDecal As ListRow
Application.ScreenUpdating = False
Set tableRowDecal = wsL.ListObjects("tblDecal").ListRows.Add
tableRowDecal.Range(1, 1).Value = cmbDecal
'sort
sort = sortTable("Lists", "tblDecal", "Decal of Truck", 1)
Application.ScreenUpdating = True
End If
End If
'check date
If IsDate(txtDate.Value) = False Then
MsgBox "Check date entered."
Exit Sub
End If
'check material entered
flagMat = checkList("tblInMaterial", "Material", cmbMaterial.Value)
'if recognized
If flagMat = True Then
Dim count As Integer
Dim tableRowMain As ListRow
Dim material As String
Dim char As String
Application.ScreenUpdating = False
'remove characters
material = cmbMaterial.Value
For count = 1 To Len(material)
char = Mid(material, count, 1)
If char = "-" Or char = "(" Or char = ")" Or char = " " Then
material = Replace(material, char, "")
count = count - 1
End If
Next
'add to table
Set tableRowMain = wsI.ListObjects("tbl" & material).ListRows.Add
tableRowMain.Range(1, 1).Value = txtDate <------------------error here
tableRowMain.Range(1, 2).Value = cmbDecal
If Left(Right(cmbState, 4), 1) = "," Then
tableRowMain.Range(1, 3).Value = Right(cmbState, 2)
Else
tableRowMain.Range(1, 3).Value = cmbState
End If
tableRowMain.Range(1, 4).Value = cmbCounty
tableRowMain.Range(1, 5).Value = cmbMunicipality
tableRowMain.Range(1, 6).Value = txtYards
tableRowMain.Range(1, 7).Value = txtTons
'sort by date
sort = sortTable("Incoming Sheet", "tbl" & material, "Date - Time", 2)
'check if empty row
If wsI.ListObjects("tbl" & material).Range.Cells(wsI.ListObjects("tbl" & material).Range.Rows.count, 1) _
= "" Then
wsI.ListObjects("tbl" & material).Range.Cells(wsI.ListObjects("tbl" & material).Range.Rows.count, 1) _
.EntireRow.Delete
End If
Else
MsgBox "Material not recognized."
Exit Sub
End If
CutCopyMode = False
Unload IncomingForm
sort = calc(wsI.OLEObjects("cmbInTotals").Object.Value, wsI.OLEObjects("cmbInType").Object.Value, _
Worksheets("Incoming Sheet"), 12)
Application.ScreenUpdating = True
wsI.ListObjects("tbl" & material).Range.Cells(1, 1).Select
ThisWorkbook.Save
MsgBox "Material successfully added."