Results 1 to 9 of 9
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Toggle Button (A2000)

    I've never used a toggle button before and now have the need to do so.

    I want to switch a graphic OLE on and off, can some-one help with the syntax.

    The object's default setting is invisible, So if I used an ordinary button it would be:

    Me.OLEObject.Visible=True

    To switch it on.

    What would it be to turn it back to false with the toggle.

    Dave

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Toggle Button (A2000)

    Hi Dave,

    The default property of a toggle button is its value, which is True if it is down, False if it is up.

    So you can use code like the following in the OnClick routine of the toggle button (named ToggleButton1 in this example):

    Me.OLEObject.Visible = ToggleButton1

    Another way to toggle something is to invert its value:

    Me.OLEObject.Visible = Not Me.OLEObject.Visible

    Regards,
    Hans

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle Button (A2000)

    Well.
    Cheers for that Hans, never thought it would be that easy.

    Thanks
    Dave

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle Button (A2000)

    Hans
    That's interesting. How would you use code to open and close a form (not a subform) from a main form with a toggle button.
    I've been using:
    togglebutton_click
    if form is open close it
    exit sub
    else
    open the form
    end sub
    I could do that with a standard button but I can see which way it is with a toggle.
    Is there a better way?
    Peter

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Toggle Button (A2000)

    You mean you can't see the form to know it's open?
    Charlotte

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Toggle Button (A2000)

    If you're looking for a way to determine in code whether a form is open, you can use the following function. It returns True if the specified form is open in Form or DataSheet mode.

    Function IsFormLoaded(ByVal strFormName As String) As Boolean
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) Then
    IsFormLoaded = Forms(strFormName).CurrentView
    End If
    End Function

    You can use it in the following form:

    If IsFormLoaded("frmMyForm") Then
    DoCmd.Close acForm, "frmMyForm", acSaveNo
    Else
    DoCmd.OpenForm "frmMyForm"
    End If

    But, to be frank, I don't think it is a good idea to use a toggle button for this. You'd have to write extra code to ensure that the state of the toggle button stays in tune with the state of the form. If the user closes the form manually, you'd have to toggle the button without firing the toggle action.

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle Button (A2000)

    Thanks Hans - that's the way I'm doing it. I just thought your inversion trick sounfded interesting.
    You're right of course, it does occasionally get out of synq' but we can live with that ( there's only 1 pc for 2 people)
    Peter

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle Button (A2000)

    Charlotte
    You can be so cutting. I'm hurt.
    (also see my response to Hans)
    Peter

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Toggle Button (A2000)

    Well, I wasn't trying to hurt. I just didn't know if the form was being opened hidden. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •