Not bad. really it is just a question of determining your logic.
Do ALL the textboxes have to filled? In other words, if you have 20 possible entry lines (combobox with company, textbox with check number, textbox with check amount), what if they only put in 11 entries. Is this an error if the remaining nine lines (18 textboxes) are blank?
I would not think so...unless of course you DO want all 20 possible entries to be filled.
So...it is not that the textbox is blank, but that a textbox is blank on a line associated with a combobox with a selected item.
You could have the comboboxes have as the first item = "Select a company". Now when you start your logic you would first test for each combobox value.
If it is NOT "Select a company", then check the value of the associated textboxes.
If it IS "Select a company", then you can ignore the associated textboxes. Both in terms of checking their values, and also any use of inadvertant values.
By associated, I mean a judicious use of control names.
Line 1:
cboCompany1 txtCompany1CheckNum txtCompany1CheckAmt
Line 2:
cboCompany2 txtCompany2CheckNum txtCompany2CheckAmt
etc.
That would make it easier to make the associations.
You check each combobox. Is it "Select a company"? Go to next combobox. It is NOT "Select a company", strip off the relevant part of the combobox name (say, a string...strCurrentcbo = "Company1"), and use that string to build a control name string ("txt" & strCurrentcbo & "CheckNum") and check that.
Code:
Dim oCtl As Control
Dim strCurrentcbo As String
For Each oCtl in Me.Controls
If TypeOf oCtl Is Combobox Then
If oCtl.Value <> "Select a company" Then
strCurrentcbo = Right(oCtl.Name, Len(oCtl.Name) - 3)
If Me.Controls("txt" & _
strCurrentcbo & "CheckNum").Text = "" Or _
Me.Controls("txt" & _
strCurrentcbo & "CheckAmt").Text = "" Then
[COLOR=red] ' either build an string array of [b]all[/b]
' missing textbox values, and display at the
' end of validation, or display one at a time
' personally I would build an array of error
' messages and display them all as ONE message[/color red]
End If
End If
End If
Next
There are of course many ways to go about this, but at least with this way if a company combobox has no company selected your validation logic does not care about the associated textboxes.
Gerry
My paintings and sculpture