+ Reply to Thread
Results 1 to 14 of 14

Userform fade not working from command buttons

Hybrid View

  1. #1
    Registered User
    Join Date
    03-30-2011
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    15

    Question Userform fade not working from command buttons

    excel 2003 running xp
    Got a userform that is activated from a command button that fades out the background so the userform really stands out.

    I have about 5 more command buttons on same page but can NOT get them to use the fade routine when their command buttons are pressed.

    kind of got it to work with Buttons but thats not what they require, prefer to use command buttons.

    ' worked with buttons
    Select Case Application.Caller
            Case "Button 32"
                'calls routine show picture which calls userform2
                Call ShowFirstAid
    Then repeated this for each Button


    Im guessing I need some kind of Class module to see which command button is pressed but stuck

    added example file to look at, any help would be great.
    Attached Files Attached Files
    Last edited by romperstomper; 07-21-2011 at 07:55 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,969

    Re: Userform fade not working from command buttons

    Can I ask why you want to use Commandbuttons rather than the more stable Forms buttons?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    03-30-2011
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    15

    Re: Userform fade not working from command buttons

    Because these command buttons are constant throughout the entire project, and you cant apply colour to form buttons.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userform fade not working from command buttons

    Quote Originally Posted by berty2000 View Post
    Because these command buttons are constant throughout the entire project, and you cant apply colour to form buttons.
    Yes you can.

    I can't see any code to fade out the background or userform
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,969

    Re: Userform fade not working from command buttons

    You could just add a public commandbutton variable to the userform's module and set that in the button_click before you show the form.

  6. #6
    Registered User
    Join Date
    03-30-2011
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    15

    Re: Userform fade not working from command buttons

    The code for the fade is all in the example spreadsheet to download.

    Can you colour the buttons in excel 2003 ?

  7. #7
    Registered User
    Join Date
    03-30-2011
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    15

    Re: Userform fade not working from command buttons

    Romperstomper can you give a coded example as not up to speed as still learning VB

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Userform fade not working from command buttons

    code change to command buttons

    Private Sub CommandButton6_Click()
        ScreenUpdating = False
        ShowDialog "FireSafety"
    End Sub
    
    Private Sub CommandButton7_Click()
        ScreenUpdating = False
        ShowDialog "FirstAid"
    End Sub
    Add this to the top of the Userform1 code module, along this the other declarations.

    Public ShowName As String
    revise ShowPicture routine
    Sub ShowPicture()
    '   Displays on top of semi-transparent UserForm
    
        If Me.ShowName = "FirstAid" Then
            FirstAid.Show
        Else
            FireSafety.Show
        End If
        Unload Me
    End Sub
    Cheers
    Andy
    www.andypope.info

  9. #9
    Registered User
    Join Date
    03-30-2011
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    15

    Re: Userform fade not working from command buttons

    Quote Originally Posted by Andy Pope View Post
    code change to command buttons

    Private Sub CommandButton6_Click()
        ScreenUpdating = False
        ShowDialog "FireSafety"
    End Sub
    
    Private Sub CommandButton7_Click()
        ScreenUpdating = False
        ShowDialog "FirstAid"
    End Sub
    Add this to the top of the Userform1 code module, along this the other declarations.

    Public ShowName As String
    revise ShowPicture routine
    Sub ShowPicture()
    '   Displays on top of semi-transparent UserForm
    
        If Me.ShowName = "FirstAid" Then
            FirstAid.Show
        Else
            FireSafety.Show
        End If
        Unload Me
    End Sub
    When I run this I get "Wrong number of arguments or invalid property assignment" have I missed something obvious.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Userform fade not working from command buttons

    I missed out this change in Module15

    Sub ShowDialog(Name As String)
        UserForm1.ShowName = Name
        UserForm1.Show
    End Sub

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,969

    Re: Userform fade not working from command buttons

    Add this to the declarations section in the userform:
    
    Public Button As MSForms.CommandButton
    and then refer to Button wherever you need it in the code.

    The ShowDialog code becomes:
    
    Sub ShowDialog(btn As MSForms.CommandButton)
        Dim frm As UserForm1
        Set frm = New UserForm1
        Set frm.Button = btn
        frm.Show
    End Sub
    and the button_click:
    Private Sub CommandButton7_Click()
    ScreenUpdating = False
    
    ShowDialog CommandButton7
    
    End Sub

  12. #12
    Registered User
    Join Date
    03-30-2011
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    15

    Re: Userform fade not working from command buttons

    Romperstomper, Starting to look good but im losing the transparency behind the form ?

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,969

    Re: Userform fade not working from command buttons

    For mine, you need to alter the Userform_Activate code to use:
        ufcap = Me.Caption
    rather than:
        ufcap = Userform1.Caption

  14. #14
    Registered User
    Join Date
    03-30-2011
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    15

    Smile Re: Userform fade not working from command buttons

    Quote Originally Posted by romperstomper View Post
    For mine, you need to alter the Userform_Activate code to use:
        ufcap = Me.Caption
    rather than:
        ufcap = Userform1.Caption
    That now works a treat, Thank you very much the effect works really well with userforms for me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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