Toggle Button Group Changing Pictures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Breixo
    New Member
    • Dec 2014
    • 11

    #1

    Toggle Button Group Changing Pictures

    First of all, I am an absolute beginner. I've got an individual "toggle button" that changes its picture according to their status.
    I tried similar sentences to got a two grouped "toggle buttons" and after many hours of testing and internet always I get the ERROR 2427.
    I would appreciate someone check the code attached and give me some suggestion.
    Merry Christmas and Happy New Year.

    Code:
    Private Sub Marco01_AfterUpdate()
    strPathToIcons = CurrentProject.Path & "\"
    Select Case Marco01.Value
    Case 1
    If tglButt01.Value = True Then 'ERROR 2427
       tglButt01.Picture = strPathToIcons & "birds.ico"       'True
    Else
       tglButt01.Picture = strPathToIcons & "birdsBW.ico"     'False
    End If
    Case 2
    If tglButt02.Value = True Then  'ERROR 2427
       tglButt02.Picture = strPathToIcons & "squirrels.ico"   'True
    Else
       tglButt02.Picture = strPathToIcons & "squirrelsBW.ico" 'False
    End If
    Case Else
    Exit Sub
    End Select
    End Sub
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3665

    #2
    Breixo,

    First, welcome to Bytes! I hope we can prove to be of some help for you.

    Second, understanding the Option Group (it certainly appears that you have an option group) control can help you with your code. Remember, that an option group is a collection of toggle buttons (or check boxes, or whatever), but those buttons have no value in and of themselves, so when you refer to those objects, you will get an error. However, the Option Group itself (Marco01) is the object that has any inherent value. So, when you use your Select Case Statement, and then refer again to the Toggle, aside from being redundant and unnecessary, you get an error, because tglButt01 has no value.

    Try this, and you should have success:
    Code:
    Private Sub Marco01_AfterUpdate()
        strPathToIcons = CurrentProject.Path & "\"
        Select Case Marco01.Value
            Case 1
                tglButt01.Picture = strPathToIcons & "birds.ico"
                tglButt02.Picture = strPathToIcons & "squirrelsBW.ico"
            Case 2
                tglButt02.Picture = strPathToIcons & "squirrels.ico"
                tglButt01.Picture = strPathToIcons & "birdsBW.ico"
        End Select
    End Sub
    Notice how we set both toggle buttons based on the value of the Option Group. Additionally, if your Option Group is properly set up, then it can only have one of two possible values (1 or 2), so there is no need for a Case Else.

    I hope this helps.

    Comment

    • Breixo
      New Member
      • Dec 2014
      • 11

      #3
      Hi, twinnyfo

      Everything is easy when the solution is known.
      Your explanations are clear and concise.
      Your code is as simple as effective.

      Thank you very much and Happy New Year

      Comment

      Working...