Empty combo box help

jeremypaule

Registered User.
Local time
Today, 15:26
Joined
Aug 21, 2006
Messages
135
When I click a button I have code (below) that checks to see if my Combo boxes are NULL (empty), and if they are it’ll prompt the user to “fill in all fields”. Right now it includes all of the combo boxes on my form. Although, I want it to only include 3 combo boxes (I have 5 on my form). How could I do this, lets say if my combo box names are cbo1, cbo2, cbo3 ?

For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acComboBox
If ctl.Value & "" = "" Then
MsgBox "You must fill in all data fields."
Exit Sub
End If
End Select
Next
 
You might consider using the "tag" property with say an "*"

If IsNull(ctl.Value) or ctl.Value = " " and ctl.Tag = "*" Then

I think thats the correct syntax..... air code. someone correct me if I'm wrong
 
You have a couple of options.

First, you could just hard code the names of the boxes to check instead of looping through all controls, like so:

Code:
If me.cbo1 & "" = "" Then
    MsgBox "Missing data in cbo1"
    Exit Sub
End If

If me.cbo2 & "" = "" Then
    msgbox "Missing  data in cbo2"
    Exit Sub
End If

etc...

If you'd rather not do that, you can just add a tag to the combo boxes you wish to check, and then modify your code as follows:

Code:
For Each ctl In Me.Controls
If ctl.Tag = "CheckMe" Then
     If ctl.Value & "" = "" Then
     MsgBox "You must fill in all data fields."
     Exit Sub
     End If
End If
Next
 

Users who are viewing this thread

Back
Top Bottom