+ Reply to Thread
Results 1 to 4 of 4

Change location of commandbuttons on multi page in userform using vba

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Change location of commandbuttons on multi page in userform using vba

    Hi all

    Can this be done?

    I have a userform with a multipage control with 12 pages. Page (0) is called Frequently Used. Pages 1 to 12 all have a number of command buttons. The code for each command button has a code which identifies which page it is on. If any command button is used at least once, I want to move that command button to the Frequently Used page (Pages(0)).

    Is this possible programatically?

    Cheers


  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Change location of commandbuttons on multi page in userform using vba

    You can copy all the controls from one multipage to another but I've never seen anything for copying/moving a single control.

    What do all the command buttons do?

    Perhaps you could have something at run-time that adds them to specific pages based on some sort of criteria.

    If you did that you would need a class module to handle the click events of the command buttons.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Re: Change location of commandbuttons on multi page in userform using vba

    Sorry about the delay in responding, Norie.

    Below is the code for two selected buttons:

    Private Sub cmdGL_6046_Click()
        
        cmdGL_6046.BackColor = 13485434: CheckNextItem = 1
        
        CCaption = cmdGL_6046.Caption: ECaption = "Telephone/Fax & Postage ": GLCode = "6046"
        
        lblNameOfSupplier.Visible = True: txtNameOfSupplier.Visible = True
        lblExistingSupplier.Visible = True: cboExistingSupplier.Visible = True
        
        Call ButtonClick: cmdAnotherItem.Visible = False ': Call Budget
        
        txtHelp.Height = 55
        txtHelp = "This is for stationary items." & vbCrLf & vbCrLf & "If this not what you want, please press the Undo button to de-select this item."
           
        MultiPage1.Pages(0).Enabled = True: MultiPage1.Value = 0
        
    End Sub
    and ...

    Private Sub cmdGL_6050_Click()
        
        cmdGL_6050.BackColor = 13485434: CheckNextItem = 1
        
        CCaption = cmdGL_6050.Caption: ECaption = "Motor & Travel ": GLCode = "6050"
        
        lblRegLocal.Visible = True: lblRegAll.Visible = True
        cboRegLocal.Visible = True: cboRegAll.Visible = True
        
        lblNameOfSupplier.Visible = True: txtNameOfSupplier.Visible = True
        lblExistingSupplier.Visible = True: cboExistingSupplier.Visible = True
        
        Call ButtonClick: cmdAnotherItem.Visible = False
        
        'MultiPage2.Visible = False:
        
        MultiPage1.Pages(2).Enabled = True: MultiPage1.Value = 2
        
    End Sub
    There are about 400 buttons in different tabs of the Multipage1 control. I think your suggestion is good, but how do I even start coding that!!!?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Change location of commandbuttons on multi page in userform using vba

    Why do you have all these command buttons?

    They appear to do basically the same thing with a few minor changes.

    What's the purpose of the form?

    Why not use a control that can handle multiple items, for example a listbox or combobox?00

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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