Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts

    disable Click event (2000 sp3)

    I searched for this but I couldn't find what I was looking for. Maybe I'm not using the right terms. If a thread exists, please let me know!
    I have a set of radio buttons on a form. Depending on the value I want to dim or undim (and enable or disable) other fields on the form (no problem). I have _Click events on the buttons. The trouble I'm having, is in my _Initialize event. When I move a saved value to one of the radio buttons it fires the _Click event. Is there a statement to disable the event that I can put before the move and then another statement I can put after the move to enable the event again? I could use this kind of statement to solve another problem where the _Initialize event is firing!
    Thanks for any help you can give me.

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

    Re: disable Click event (2000 sp3)

    You could use a module-level variable to keep track of whether the form is being initialized:
    <code>
    Private blnInitializing As Boolean

    Private Sub OptionButton1_Click()
    ' get out if initializing
    If blnInitializing Then Exit Sub
    ' action for option button
    If Me.OptionButton1 = True Then
    ' code here
    Else
    ' other code here
    End If
    End Sub

    Private Sub UserForm_Initialize()
    ' set flag
    blnInitializing = True
    ' set value of controls
    Me.OptionButton1 = True
    ' clear flag
    blnInitializing = False
    End Sub</code>

  3. #3
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: disable Click event (2000 sp3)

    Wow! A simple solution! I was looking so hard for what I didn't know that I forgot to use something simple that I did know! Thanks for being the voice of reason. Most helpful.

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: disable Click event (2000 sp3)

    Wouldn't

    <pre> Application.EnableEvents = False
    ' Whatever code would fire the event
    Application.EnableEvents = True
    </pre>


    Be a lot simpler?
    Legare Coleman

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

    Re: disable Click event (2000 sp3)

    That's what I thought at first too. But EnableEvents works for Excel worksheet and workbook events, not for userform events.

  6. #6
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: disable Click event (2000 sp3)

    Interesting! All along I thought that user forms were part of the Application.
    Legare Coleman

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

    Re: disable Click event (2000 sp3)

    No, userforms not part of Excel itself, they are in a separate library (Microsoft Forms 2.0 Object Library, filename FM20.DLL), shared by various Office applications.

Posting Permissions

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