Hello.
I have the following code which runs upon the click of a button.
It looks at the repsonses made within the form and checks for errors.
If errors are found then it highlights them red and focuses on them.
The code does work, but it just looks a bit messy and long winded, especially given there are probably another 100+ IF checks to be added in.
Also I am having trouble with the following part not working if anything other than none is selected in the combobox.
Code:
If cboEntranceDoorsFlats.Value <> "None" And Len(Me.txtEntranceDoorsFlatsQuant & "") = 0 Then
Me.txtEntranceDoorsFlatsQuant.BackColor = vbRed
Me.txtEntranceDoorsFlatsQuant.SetFocus
But heres an example of the full code as it is now.
Code:
Private Sub btnCompleteSurvey_Click()
If IsNull(cboSurveyor.Value) Then
Me.cboSurveyor.BackColor = vbRed
Me.cboSurveyor.SetFocus
If IsNull(txtSurveyDate.Value) Then
Me.txtSurveyDate.BackColor = vbRed
Me.txtSurveyDate.SetFocus
If IsNull(cboNumberofBedrooms.Value) Then
Me.cboNumberofBedrooms.BackColor = vbRed
Me.cboNumberofBedrooms.SetFocus
If IsNull(cboNumberofBedSpaces.Value) Then
Me.cboNumberofBedSpaces.BackColor = vbRed
Me.cboNumberofBedSpaces.SetFocus
If IsNull(cboNumberofHabitableRooms.Value) Then
Me.cboNumberofHabitableRooms.BackColor = vbRed
Me.cboNumberofHabitableRooms.SetFocus
If IsNull(cboNumberofHeatedRooms.Value) Then
Me.cboNumberofHeatedRooms.BackColor = vbRed
Me.cboNumberofHeatedRooms.SetFocus
If Len(Me.txtGroundfloorarea & "") = 0 Then
Me.txtGroundfloorarea.BackColor = vbRed
Me.txtGroundfloorarea.SetFocus
If Len(Me.txtRoomheight & "") = 0 Then
Me.txtRoomheight.BackColor = vbRed
Me.txtRoomheight.SetFocus
If IsNull(cboEntranceDoorsFlats.Value) Then
Me.cboEntranceDoorsFlats.BackColor = vbRed
Me.cboEntranceDoorsFlats.SetFocus
If cboEntranceDoorsFlats.Value <> "None" And Len(Me.txtEntranceDoorsFlatsQuant & "") = 0 Then
Me.txtEntranceDoorsFlatsQuant.BackColor = vbRed
Me.txtEntranceDoorsFlatsQuant.SetFocus
If cboEntranceDoorsFlats.Value <> "None" And Len(Me.txtEntranceDoorsFlatsRenewYear & "") = 0 Then
Me.txtEntranceDoorsFlatsRenewYear.BackColor = vbRed
Me.txtEntranceDoorsFlatsRenewYear.SetFocus
MsgBox ("Survey contains Missing or Incorrect Data! Please complete all fields in RED and click Complete Survey!")
Me.txtSurveyStatus = "Incomplete"
Me.txtSurveyStatus.ForeColor = vbRed
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
If Me.cboSurveyor.Value <> "" Then
If Me.txtSurveyDate.Value <> "" Then
If Me.cboNumberofBedrooms.Value <> "" Then
If Me.cboNumberofBedSpaces.Value <> "" Then
If Me.cboNumberofHabitableRooms.Value <> "" Then
If Me.cboNumberofHeatedRooms.Value <> "" Then
If Me.txtGroundfloorarea.Value <> "" Then
If Me.txtRoomheight.Value <> "" Then
If Me.cboEntranceDoorsFlats.Value <> "" Then
If Me.txtEntranceDoorsFlatsQuant.Value <> "" Then
MsgBox "Survey Complete Successfully"
Me.txtSurveyStatus = "Complete"
Me.txtSurveyStatus.ForeColor = vbGreen
Me.txtSurveyStatus.SetFocus
MsgBox ("Survey contains Missing or Incorrect Data! Please complete all fields in RED and click Complete Survey!")
Me.txtSurveyStatus = "Incomplete"
Me.txtSurveyStatus.ForeColor = vbRed
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
Help much appreciated.