After I fill in the three boxes with drop downs I have a pop up after I click the enter button with a message that says Qualification....Please select the inspection type from drop down. It highlights that box in red and populates this long number in the box. I'm not sure where the number comes from as it's a drop down list of text. It shouldn't even throw this message box as a inspection type was filled in.
Option Explicit
Function ValidateForm() As Boolean
monthinspected.BackColor = vbWhite
Inspector.BackColor = vbWhite
inspectiontype = vbWhite
ValidateForm = True
If monthinspected.Text <> "January" And monthinspected.Text <> "February" And monthinspected.Text <> "March" And monthinspected.Text <> "April" And monthinspected.Text <> "May" And monthinspected.Text <> "June" And monthinspected.Text <> "July" And monthinspected.Text <> "August" And monthinspected.Text <> "September" And monthinspected.Text <> "October" And monthinspected.Text <> "November" And monthinspected.Text <> "December" Then
MsgBox "Please select the correct month from drop down.,", vbOKOnly + vbInformation, "Qualification"
monthinspected.BackColor = vbRed
monthinspected.Activate
ValidateForm = False
ElseIf Inspector.Text <> "Chuck" And Inspector.Text <> "Rob" And Inspector.Text <> "Other" Then
MsgBox "Please select the correct Inspector from drop down.,", vbOKOnly + vbInformation, "Qualification"
Inspector.BackColor = vbRed
Inspector.Activate
ValidateForm = False
ElseIf inspectiontype.Text <> "Footings" And inspectiontype.Text <> "Foundation" And inspectiontype.Text <> "Underground Plumbing" And inspectiontype.Text <> "Underground Heating" And inspectiontype.Text <> "Framing" And inspectiontype.Text <> "Rough Plumbing" And inspectiontype.Text <> "Rough Heating" And inspectiontype.Text <> "Rough Electric" And inspectiontype.Text <> "Roof" And inspectiontype.Text <> "Electrical Service" And inspectiontype.Text <> "Electrical Temporary" And inspectiontype.Text <> "Final" And inspectiontype.Text <> "Pre Construction Inspection" And inspectiontype.Text <> "Courtesy Inspection" And inspectiontype.Text <> "Unsafe" Then
MsgBox "Please select the inspection type from drop down.,", vbOKOnly + vbInformation, "Qualification"
inspectiontype.BackColor = vbRed
inspectiontype.Activate
ValidateForm = False
End If
End Function
Function Reset()
Application.ScreenUpdating = False
monthinspected.Text = ""
monthinspected.BackColor = vbWhite
Inspector.Text = ""
Inspector.BackColor = vbWhite
inspectiontype = ""
inspectiontype.BackColor = vbWhite
Application.ScreenUpdating = True
End Function
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim iRow As Long
iRow = Sheets("Data").Range("A2:A1048576").End(xlUp).Row + 1
If ValidateForm = True Then
With ThisWorkbook.Sheets("Data")
.Range("A" & iRow).Value = iRow - 1
.Range("B" & iRow).Value = monthinspected.Text
.Range("C" & iRow).Value = Inspector.Text
.Range("D" & iRow).Value = inspectiontype.Text
End With
Call Reset
Else
Application.ScreenUpdating = True
Exit Sub
End If
Application.ScreenUpdating = True
End Sub
Option Explicit
Function ValidateForm() As Boolean
monthinspected.BackColor = vbWhite
Inspector.BackColor = vbWhite
inspectiontype = vbWhite
ValidateForm = True
If monthinspected.Text <> "January" And monthinspected.Text <> "February" And monthinspected.Text <> "March" And monthinspected.Text <> "April" And monthinspected.Text <> "May" And monthinspected.Text <> "June" And monthinspected.Text <> "July" And monthinspected.Text <> "August" And monthinspected.Text <> "September" And monthinspected.Text <> "October" And monthinspected.Text <> "November" And monthinspected.Text <> "December" Then
MsgBox "Please select the correct month from drop down.,", vbOKOnly + vbInformation, "Qualification"
monthinspected.BackColor = vbRed
monthinspected.Activate
ValidateForm = False
ElseIf Inspector.Text <> "Chuck" And Inspector.Text <> "Rob" And Inspector.Text <> "Other" Then
MsgBox "Please select the correct Inspector from drop down.,", vbOKOnly + vbInformation, "Qualification"
Inspector.BackColor = vbRed
Inspector.Activate
ValidateForm = False
ElseIf inspectiontype.Text <> "Footings" And inspectiontype.Text <> "Foundation" And inspectiontype.Text <> "Underground Plumbing" And inspectiontype.Text <> "Underground Heating" And inspectiontype.Text <> "Framing" And inspectiontype.Text <> "Rough Plumbing" And inspectiontype.Text <> "Rough Heating" And inspectiontype.Text <> "Rough Electric" And inspectiontype.Text <> "Roof" And inspectiontype.Text <> "Electrical Service" And inspectiontype.Text <> "Electrical Temporary" And inspectiontype.Text <> "Final" And inspectiontype.Text <> "Pre Construction Inspection" And inspectiontype.Text <> "Courtesy Inspection" And inspectiontype.Text <> "Unsafe" Then
MsgBox "Please select the inspection type from drop down.,", vbOKOnly + vbInformation, "Qualification"
inspectiontype.BackColor = vbRed
inspectiontype.Activate
ValidateForm = False
End If
End Function
Function Reset()
Application.ScreenUpdating = False
monthinspected.Text = ""
monthinspected.BackColor = vbWhite
Inspector.Text = ""
Inspector.BackColor = vbWhite
inspectiontype = ""
inspectiontype.BackColor = vbWhite
Application.ScreenUpdating = True
End Function
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim iRow As Long
iRow = Sheets("Data").Range("A2:A1048576").End(xlUp).Row + 1
If ValidateForm = True Then
With ThisWorkbook.Sheets("Data")
.Range("A" & iRow).Value = iRow - 1
.Range("B" & iRow).Value = monthinspected.Text
.Range("C" & iRow).Value = Inspector.Text
.Range("D" & iRow).Value = inspectiontype.Text
End With
Call Reset
Else
Application.ScreenUpdating = True
Exit Sub
End If
Application.ScreenUpdating = True
End Sub