+ Reply to Thread
Results 1 to 6 of 6

Peculiar behavior — button on userform

Hybrid View

  1. #1
    Registered User
    Join Date
    11-16-2011
    Location
    Vermont
    MS-Off Ver
    Excel 365
    Posts
    57

    Peculiar behavior — button on userform

    I have a workbook that opens as "Application.Visible = False." A userform opens instead. On the userform is a toggle button to hide or unhide the spreadsheet.. So far, everything works flawlessly. Toggle in, toggle out, shows or hides.

    The glitch comes if the userform is closed for some reason. If that happens, there is a button on the spreadsheet to call the userform, When that is done, if the toggle button is pressed, nothing happens. It has to be pressed for a second time before it will work. After that, it again works flawlessly. It's only that first click after re-calling the form that it misbehaves.

    I figure there has to be some conflict in the code that's confusing it, but I can't find what it is. The code for the toggle is as follows—
    
    Private Sub ToggleShow_Hide_Click()
    
    If ToggleShow_Hide.Value = False Then
        Call Hide_Window
        Call Show_Userform1
            Else
        Call Show_Window
    
        End If
    
    End Sub
    —and the three "Calls" are these:
    Option Explicit
    
    Sub Hide_Window()
    
        Application.Visible = False
    
    End Sub
    
    Sub Show_Window()
    
        Application.Visible = True
        
    End Sub
    
    
    Sub Show_Userform1()
    
        If UserForm1.Visible Then
            Exit Sub
                Else
            UserForm1.Show vbModeless
        End If
    
    End Sub
    Any help here? (There's more code to the Userform than this, but I can't find any that interacts with the toggle button in question. I hate to post a whole wall of text that's not needed.)
    Nick

    (I'm only an egg)

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,459

    Re: Peculiar behavior — button on userform

    In the code you have posted, it doesn't appear that you reset the ToggleShow_Hide variable value. It may be that you do it elsewhere but I’m guessing that it isn't set to the correct value when the form is closed.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    11-16-2011
    Location
    Vermont
    MS-Off Ver
    Excel 365
    Posts
    57

    Re: Peculiar behavior — button on userform

    Thank you Trevor. You'll have to bear with me—I don't know code very well. I know how to do some things, and I'm getting better, but half the time I don't really understand what it is I'm doing. So I'm sure you're right. I didn't reset the value because I don't know how (let alone know that it was necessary ) I'm researching that now, but any pointers you can give me would be more than welcome.
    Last edited by Nick Vittum; 02-18-2020 at 06:03 PM.

  4. #4
    Registered User
    Join Date
    11-16-2011
    Location
    Vermont
    MS-Off Ver
    Excel 365
    Posts
    57

    Re: Peculiar behavior — button on userform

    (just wanted to give this a bump, since I haven't been able to find the answer yet)

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,459

    Re: Peculiar behavior — button on userform

    I would imagine it should be something like ...

    Option Explicit
    
    Sub Hide_Window()
    
        Application.Visible = False
        ToggleShow_Hide.Value = True
    
    End Sub
    
    Sub Show_Window()
    
        Application.Visible = True
        ToggleShow_Hide.Value = False
    
    End Sub

  6. #6
    Registered User
    Join Date
    11-16-2011
    Location
    Vermont
    MS-Off Ver
    Excel 365
    Posts
    57

    Re: Peculiar behavior — button on userform

    Thank you again, Trevor

    I tried inserting those toggle values in the Show and Hide macros, as you suggested. Then it wanted me to define "ToggleShow_Hide" so I defined it as "ToggleButton" (seemed logical). Like this:
    Option Explicit
    Dim ToggleShow_Hide As ToggleButton
    
    Sub Hide_Window()
    
        Application.Visible = False
        ToggleShow_Hide.Value = True
    
    End Sub
    
    Sub Show_Window()
    
        Application.Visible = True
        ToggleShow_Hide.Value = False
        
    End Sub
    —but then it froze up on ToggleShow_Hide.Value, with the following message:
    Attachment 663403. I'm so confused....Am I defining it wrong? Do I need another line to my definitions?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Numbered list button behavior
    By Jacc in forum Word Formatting & General
    Replies: 3
    Last Post: 02-24-2017, 08:59 AM
  2. [SOLVED] Behavior of Buttons in userform
    By tommymc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-07-2012, 10:19 AM
  3. Different behavior if I close userform via button or x
    By nohero in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-05-2011, 04:04 PM
  4. Need macro's behavior to depend on button pushed
    By JChandler22 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-29-2010, 11:46 AM
  5. Inconsistant Behavior using a UserForm
    By vivictis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-04-2008, 03:50 PM
  6. Userform strange behavior
    By Shaun_email in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-09-2007, 07:47 PM
  7. [SOLVED] Odd UserForm Behavior
    By Gene in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-03-2006, 11:15 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1