+ Reply to Thread
Results 1 to 5 of 5

Click a Spin Button via another button?

Hybrid View

NewYears1978 Click a Spin Button via... 02-19-2015, 02:04 AM
Alf Re: Click a Spin Button via... 02-19-2015, 03:31 AM
NewYears1978 Re: Click a Spin Button via... 02-19-2015, 03:33 AM
Andy Pope Re: Click a Spin Button via... 02-19-2015, 04:30 AM
NewYears1978 Re: Click a Spin Button via... 02-19-2015, 04:37 AM
  1. #1
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Click a Spin Button via another button?

    I have a userform that has a Spin Button in it, and I am trying to hit a Command Button (or Label in this case) and make it run the SpinDown and then Another to run the SpinUp, but this doesn't appear to work.

    Is this not possible?

    My Spin Buttons look like this:
    Public Sub SpinButton1_SpinDown()
     'SCAN FORWARD
     
      ShowCurrentRecord
    
        With New MSForms.DataObject
            .SetText TextBox1.Text
            .PutInClipboard
        End With
    
    End Sub
    
    Public Sub SpinButton1_SpinUp()
     'SCAN BACKWARD
     
      ShowCurrentRecord
    
        With New MSForms.DataObject
            .SetText TextBox1.Text
            .PutInClipboard
        End With
      
    End Sub
    I tried this:
    Private Sub Label14_Click()
    SpinButton1_SpinDown
    End Sub
    and

    Private Sub Label14_Click()
    UserForm1.SpinButton1_SpinDown
    End Sub
    Thanks in advance for any help.

    (Of you need the reasoning behind this, it is so I can use better visuals for my Spin buttons than the default ugly ones)
    Last edited by NewYears1978; 02-19-2015 at 03:52 PM.

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,794

    Re: Click a Spin Button via another button?

    Quck (and maybe stupid) question but have you assigned the macro "Public Sub Spinbutton" to the spin button?

    Alf

  3. #3
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Click a Spin Button via another button?

    There are no stupid questions for me...I am a complete newb with no training so I am learning as I go..I don't even know how to do what you suggest.

    My buttons are all in a userform though so I don't know how to assign macros (thought that was only done when buttons were in the excel document)


    The SpinButton codes above work on their own when clicking the actual spin button. I just want to click a separate button and it do the same thing as if I had clicked the spin button..if that makes sense.

    I will attach form so it makes more sense you'll see the working spin button and the 2 labels I tried to use instead.
    Attached Files Attached Files
    Last edited by NewYears1978; 02-19-2015 at 03:35 AM.

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

    Re: Click a Spin Button via another button?

    As the code stands at the moment you would need to modify the label click routines

    Private Sub Label13_Click()
        If SpinButton1.Value - 1 >= SpinButton1.Min Then
            SpinButton1.Value = SpinButton1.Value - 1
            SpinButton1_SpinDown
        End If
    End Sub
    Private Sub Label14_Click()
        If SpinButton1.Value + 1 <= SpinButton1.Max Then
            SpinButton1.Value = SpinButton1.Value + 1
            SpinButton1_SpinUp
        End If
    End Sub
    Perhaps a cleaner way would be to remove the spinup and spindown routines and use the change event instead.
    Private Sub Label13_Click()
        If SpinButton1.Value - 1 >= SpinButton1.Min Then
            SpinButton1.Value = SpinButton1.Value - 1
        End If
    End Sub
    Private Sub Label14_Click()
        If SpinButton1.Value + 1 <= SpinButton1.Max Then
            SpinButton1.Value = SpinButton1.Value + 1
        End If
    End Sub
    Private Sub SpinButton1_Change()
      
      ShowCurrentRecord
    
    If TextBox1.Text = "" Then
        
    Else
        With New MSForms.DataObject
            .SetText TextBox1.Text
            .PutInClipboard
        End With
    End If
    
    End Sub
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Click a Spin Button via another button?

    Andy thanks for your reply. Caught me right before going off to bed. I will try tomorrow and let you know how it works out. Much appreciated.

    Edit:

    I went ahead and tried, first one works perfect. The second I wasn't sure what to remove. There are several calls in the module for SpinButton and they are required for the other buttons to work so for now I went with the first option.

    However cleaner is better so I'd like to figure out how to make the other option work.
    Last edited by NewYears1978; 02-19-2015 at 04:44 AM.

+ 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] Help with Spin Button. Set Spin button starting value based on a text box value
    By etuckram in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-18-2014, 10:05 AM
  2. [SOLVED] Double Click Spin Button
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-27-2012, 02:40 PM
  3. Replies: 2
    Last Post: 03-12-2008, 06:52 PM
  4. Spin Button:spin cells A7
    By ice in forum Excel General
    Replies: 1
    Last Post: 03-16-2007, 02:23 PM
  5. [SOLVED] Create floating button based on button click in menu
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2005, 02:05 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