Checkboxes - automated looping?

pat_nospam

Registered User.
Local time
Today, 17:36
Joined
Oct 14, 2003
Messages
151
Okay - I know there must be a programatic way to do this without the lengthy checks. Here is the code I am working with in order to show a picture.

Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

    If IsNull(Me!Court1) Or Me!Court1 = "" Or IsNull(Me!Court2) Or Me!Court2 = "" Or IsNull(Me!Court3) Or Me!Court3 = "" Or IsNull(Me!Court4) Or Me!Court4 = "" Or IsNull(Me!Court5) Or Me!Court5 = "" Or IsNull(Me!Court6) Or Me!Court6 = "" Or IsNull(Me!Court7) Or Me!Court7 = "" Or IsNull(Me!Court8) Or Me!Court8 = "" Or IsNull(Me!Court9) Or Me!Court9 = "" Or IsNull(Me!Court10) Or Me!Court10 = "" Or IsNull(Me!Court11) Or Me!Court11 = "" Or IsNull(Me!Court12) Or Me!Court12 = "" Or IsNull(Me!Court13) Or Me!Court13 = "" Or IsNull(Me!Court14) Or Me!Court14 = "" Then
        Me!Picture.Picture = GetPathPart & "1.jpg"
    Else
        Me!Picture.Picture = GetPathPart & Me!Court & ".jpg"
    End If
            
Exit_Form_Open:
    Exit Sub
    
Err_Form_Open:
    MsgBox Err.Description
    Resume Exit_Form_Open
End Sub

How can I check if the 14 checkboxes are populated, without manually checking each one. Then, after checking them, if one is populated, how do I tell my Else statement which one to grab (i.e. Me!Picture.Picture = GetPathPart & Me!Court# & ".jpg"

Thanks for the assist
 
pat_nospam said:
How can I check if the 14 checkboxes are populated, without manually checking each one. Then, after checking them, if one is populated, how do I tell my Else statement which one to grab (i.e. Me!Picture.Picture = GetPathPart & Me!Court# & ".jpg"

pat_nospam,

If you are only allowing one checkbox to be populated/ticked at any one time then you would be better off using an option group rather than the multitude of checkboxes.

You could then use a 'Select case' statement to verify which option was checked and load the relevant picture.

If you want the possibility to not have any options checked then simply don't assign a default value to the option group and load your 'standard' picture using the case else part of the select case statement.

Look for help on option groups and select case statements to get you moving in the right direction.

Cheers

Flyer
 
And bear in mind that the Form_Open event isn't the one you want to do this code in because the records haven't yet been loaded into the form and therefore the checkboxes won't be bound yet.
 
How can I use an option group (I did this initially), and allow the user to select multiple checkboxes. I need to be able to have more than one court selected at a time.

As always, you guys rock!
 
pat_nospam said:
How can I use an option group (I did this initially), and allow the user to select multiple checkboxes.

You can't.
 
pat_nospam said:
How can I use an option group (I did this initially), and allow the user to select multiple checkboxes. I need to be able to have more than one court selected at a time.

As Mile-O correctly states, you can't.

See the first line of my reply
If you are only allowing one checkbox to be populated/ticked at any one time then you would be better off using an option group rather than the multitude of checkboxes.
 
This is along the lines of what you want but there are a few things with your code and question that don't add up:

  • A control on a form called Picture is not a good name for anything as forms have their own Picture property which may become mixed up;
  • Checking the values of a checkbox - unless you have one in Triple State (which I doubt) then the checkbox won't have a Null value and it certainly won't have a Null String value - it'll be False or True;
  • I don't kow what GetPathPart is if it's not dimensioned within the subroutine - I know what it is but I question why it's not declared; and if it is declared then I question why at form level or public;
  • Trying to put the value of a checkbox into a file's pathname won't work unless the file is called 0.jpg or -1.jpg;
  • It almost sounds as if you have checkboxes and textboxes confused;

Code:
Dim ctl As Control
For Each ctl In Me
    If ctl.ControlType = acCheckBox Then
        If ctl = False Then
            Me.Picture.Picture = GetPathPart & "1.jpg"
        Else
            Me.Picture.Picture = GetPathPart & ctl & ".jpg"
        End If
    End If
Next
 
Last edited:

Users who are viewing this thread

Back
Top Bottom