+ Reply to Thread
Results 1 to 2 of 2

Problem Using New Button On User Form

  1. #1
    Registered User
    Join Date
    04-13-2019
    Location
    Beaumont, TX
    MS-Off Ver
    2K Excel, Word
    Posts
    5

    Problem Using New Button On User Form

    Environment: Windows 10, Excel/Office 2K, The workbook was created over 15 years ago, probably on an earlier version of Excel: it has worked fairly well and been revised many times over that time.

    The workbook is where I keep my personal, household budget and expenses. There are sheets for each calendar year and others for other purposes, like keeping track of the charges on my individual credit cards. So when I enter a new credit card expense or convert a scheduled one to an actual credit card expense, I use a User Form which activates VBA macros to take all the steps necessary for that entry, including adding it to the appropriate sheet for that credit card. This has worked well for many years.

    This situation has come up more than once when I attempt to add a new button on this or another user form for a new credit card. First I create that new button on the user form by copying one of the existing ones and changing all the appropriate entries in it's table. Then I go to the sections of the VBA code which handle that button press and add a new "else if" condition to cover the new button. I do this by copying the existing code and just changing the name of the button. Sometimes this works but other times I get an error window pop-up that says the method is not defined or something like that.

    Here are the two sections of code where these changes were made:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    The added lines are commented out as they were not working. The macro works perfectly for all the other credit card buttons on the user form.

    OK, now here is the "kicker", yesterday, when I created the new additions they did not work. Excel even crashed when I was trying to work on them. But today, while writing this post, I reactivated the new lines of code and they worked perfectly. Nothing has changed except to remove the exclamation points at the beginning of each line so that the code would be used. I made a quick test and it converted the entry perfectly: the amount of the credit card transaction was added to that sheet just as it should have been.

    Can anyone tell me what is going on here? I would really love to understand the use of VBA objects better. This button is a VBA object, isn't it? Or have i committed some syntax error? And what can I do the next time to avoid this difficulty?
    Last edited by EPAIII; 04-13-2019 at 01:22 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Problem Using New Button On User Form

    Welcome to the Forum EPAIII !

    I can't tell from this code what the problem is. I think you have overdiagnosed the problem--it probably originates somewhere else, so reviewing this particular code won't resolve it. The phrase "changing all the appropriate entries in it's table" comes out of nowhere and there is no context to understand what it means. You referred to "sections of the VBA code which handle that button press" but there are no Click events in the code you showed. We can't tell how this code is invoked, because we don't see the Sub statement.

    I am going to suggest you make a copy of your file, delete all the data for privacy reasons, and attach it here so we can see your form and all of your code. The paper clip icon does not work for attachments. To attach a file, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.

    I will also add that it is a design problem that you have to add a new button in order to add a credit card. The user interface design should be more robust against change. For example, have a list of credit cards on a worksheet, and then then the user form uses a dropdown list to select one of them for action. This could (and should) be designed so that you can add a credit card with absolutely no code changes.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. Add Search Button in User Form
    By M. Shahbaz in forum Excel General
    Replies: 2
    Last Post: 06-10-2017, 05:09 AM
  2. [SOLVED] OK button in user form
    By twckfa16 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-22-2015, 05:40 PM
  3. [SOLVED] User-Form Problem: User can select headers in User Form (I want Header/no way to select)
    By navialivad in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2014, 10:24 AM
  4. [SOLVED] User Form - Hyperlink Button within a Form, to create a Link on a Designated Cell
    By Sinalk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2013, 07:29 AM
  5. VBA User Form - Linking Close Button and Cancel Button
    By nivassrii in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-26-2011, 07:05 AM
  6. User Form button
    By lapot in forum Excel General
    Replies: 0
    Last Post: 06-07-2007, 06:06 AM
  7. [SOLVED] User form x button
    By Greg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2006, 12:00 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