Hi all,
I have a code which checks if the contents of a combobox match a textbox, if so, it checks to see if another text box is empty, and return a warning if it is. I have got this to work by creating IF statements for each individual check but thought there must be an easier way to do it using loops but have not been able to work out how to do it. My code is below, there are 8 textboxes in the first critera, and another 8 in the second, if combobox equals textbox 1 it checks textbox 9, if it equals textbox 2 it checks textbox 10 and so on, up to checking textbox 8 to check textbox 16 (as 1-8 is the first criteria and 9-16 is the second).
Any help would be greatly appreciated.
Private Sub ReportButton_Click()
If ComboBox.Value = Me.TextBox1 Then
If Me.TextBox9.Value = "" Then
MsgBox ("There is no text"), vbExclamation
Exit Sub
End If
End If
If ComboBox.Value = Me.TextBox2 Then
If Me.TextBox10.Value = "" Then
MsgBox ("There is no text"), vbExclamation
Exit Sub
End If
End If
If ComboBox.Value = Me.TextBox3 Then
If Me.TextBox11.Value = "" Then
MsgBox ("There is no text"), vbExclamation
Exit Sub
End If
End If
If ComboBox.Value = Me.TextBox4 Then
If Me.TextBox12.Value = "" Then
MsgBox ("There is no text"), vbExclamation
Exit Sub
End If
End If
If ComboBox.Value = Me.TextBox5 Then
If Me.TextBox13.Value = "" Then
MsgBox ("There is no text"), vbExclamation
Exit Sub
End If
End If
If ComboBox.Value = Me.TextBox6 Then
If Me.TextBox14.Value = "" Then
MsgBox ("There is no text"), vbExclamation
Exit Sub
End If
End If
If ComboBox.Value = Me.TextBox7 Then
If Me.TextBox15.Value = "" Then
MsgBox ("There is no text"), vbExclamation
Exit Sub
End If
End If
If ComboBox.Value = Me.TextBox8 Then
If Me.TextBox16.Value = "" Then
MsgBox ("There is no text"), vbExclamation
Exit Sub
End If
End If
End Sub
Bookmarks