+ Reply to Thread
Results 1 to 7 of 7

How do i test if a form (not MsgBox) button is clicked?

  1. #1
    Registered User
    Join Date
    01-20-2022
    Location
    New York, USA
    MS-Off Ver
    2013, 2016
    Posts
    6

    How do i test if a form (not MsgBox) button is clicked?

    Hello,
    I have an Excel form that displays records from an external file. The form has these buttons to traverse the records:

    [<<] , [ < ] , [ > ] , [>>] (viz. btnFirst, btnPrevious, btnNext, btnLast)

    The buttons are not assigned to macros; instead they are part of the VBA code (below). How do I properly check for a button press?

    Thank you.


    Please Login or Register  to view this content.

  2. #2
    Forum Contributor GWteB's Avatar
    Join Date
    12-13-2021
    Location
    GMT +1
    MS-Off Ver
    2013
    Posts
    136

    Re: How do i test if a form (not MsgBox) button is clicked?

    Hi Platempole, welcome to ExcelForum!

    Excel is event driven. The click events of commandbuttons on a userform are exposed so you can use them without the need of assigning macros to your buttons. Using a loop isn't needed either.
    Last edited by GWteB; 01-20-2022 at 06:06 PM.

  3. #3
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,410

    Re: How do i test if a form (not MsgBox) button is clicked?

    @Platempole, see big yellow banner - upload your actual workbook - then we can give you a context related solution.
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

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

    Re: How do i test if a form (not MsgBox) button is clicked?

    If you double click on any of the buttons when in design view you should then see a code stub like this.
    Please Login or Register  to view this content.
    This is where the code for the click event for a button, in this case btnFirst, should go.

    Note - do not use names for variables that are the same as controls on the form.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    01-20-2022
    Location
    New York, USA
    MS-Off Ver
    2013, 2016
    Posts
    6

    Re: How do i test if a form (not MsgBox) button is clicked?

    Appreciate all your responses. Norie, thanks for your input; working on it...

  6. #6
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,525

    Re: How do i test if a form (not MsgBox) button is clicked?

    You can also use the ActiveControl property of the UserForm object. E.g:
    Please Login or Register  to view this content.
    Artik

  7. #7
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,410

    Re: How do i test if a form (not MsgBox) button is clicked?

    If the form has numerous buttons you could set up a 'Button Class module' to test which is 'clicked' (saves individual code for each button if actions are common in nature).
    Two files attached, one simple one demonstrating the actions just identifying the buttons pressed, the other shows the usage in my calendar intercepting the 42 day buttons (double click in column 'A' or 'B' for pop-up calendar).
    Attached Files Attached Files

+ 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] Capture name of a userform button after it has been clicked and opened another form
    By Jerbinator in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-31-2016, 10:09 AM
  2. Command Button clicked - add test to cell
    By mklindquist0815 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2016, 07:40 PM
  3. [SOLVED] Select a certain cell(base on condition) once a form button is clicked.
    By miss_chloe in forum Excel General
    Replies: 3
    Last Post: 11-29-2015, 05:35 AM
  4. Need to run macros depending on msgbox button clicked
    By rosshkerr in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-01-2012, 06:07 AM
  5. Showing preset Worksheets when Cmd Button clicked in user form
    By niall4488 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-15-2011, 07:22 PM
  6. Using a Form Button to add 1 to a cell each time it is clicked
    By a.mack123 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-14-2010, 03:16 AM
  7. [SOLVED] Code needed to test if user clicked a button
    By Subs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2005, 10:05 AM

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