+ Reply to Thread
Results 1 to 12 of 12

How to reference generic object for AfterUpdate()

  1. #1
    Registered User
    Join Date
    11-19-2012
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    9

    How to reference generic object for AfterUpdate()

    I'm new to VBA, and I hope I can make my question clear. I've used AfterUpdate() for error-checking in userforms with one or two textboxes, but now I have a form with around 50 textboxes, all of which will need identical error-checking. One awful solution would be to make 50 copies of the error checking code:

    Please Login or Register  to view this content.
    There must be an easy way to say something like:

    Please Login or Register  to view this content.
    Muchas thanks for any ideas...

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to reference generic object for AfterUpdate()

    If they are all named in sequential order then use something like this:

    Please Login or Register  to view this content.
    Of course this is only to get you going and will need tweaking. If you still need help then please upload a sample and give more details.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    11-19-2012
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to reference generic object for AfterUpdate()

    Thanks, abousetta. I've thought about doing something like you suggested, but I don't think it's quite what I'm looking for. What I want to do is a quick error check on user-entered data in textboxes in a form. When they enter a value in a box, is it in the proper format? If not, then give an error message and give them another chance. If they still don't get it right, then restore either the previous values or default values, depending on system state. AfterUpdate() is the perfect tool...or would be perfect if I could figure out how to associate a single "AfterUpdate()" function with a group of objects rather than just a specific named object (i.e., ObjectBelongingToCertainGroup_AfterUpdate() rather than fifty copies of SpecificNamedObject_AfterUpdate() with identical Sub code but slightly different names.

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to reference generic object for AfterUpdate()

    You might be able to do that with a Class sub but I'm not at all familiar with that.

  5. #5
    Registered User
    Join Date
    11-19-2012
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to reference generic object for AfterUpdate()

    Excellent. I'm sure that's right. It's not clear to me how to do it, but thank-you for pointing me in the (probably) right direction.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How to reference generic object for AfterUpdate()

    you can't use afterupdate (or exit) with a class. if you declare a withevents textbox the event is not available and you cannot declare a generic msforms.control object (which owns the event) withevents. you'd have to use another event, such as the change event or keyup, or approach things differently
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  7. #7
    Registered User
    Join Date
    11-19-2012
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to reference generic object for AfterUpdate()

    So AfterUpdate() always requires a specific, concrete object, a la SpecificObject_AfterUpdate()?

    "change" and "keyup" seem pretty aggressive, but they'd probably work fine here. Thanks much!

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How to reference generic object for AfterUpdate()

    unfortunately yes-it's a major annoyance!

  9. #9
    Registered User
    Join Date
    11-19-2012
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to reference generic object for AfterUpdate()

    Sigh. It seems like there are plenty of those...

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How to reference generic object for AfterUpdate()

    this one is usually really hard to work around though unlike many

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How to reference generic object for AfterUpdate()

    If you're interested in a workaround, there's a very long thread on this over at Mr Excel forums with some working chide, it's quite old and a while sine I read it, but I seem to think it's a lot of work

  12. #12
    Registered User
    Join Date
    11-19-2012
    Location
    Oregon
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to reference generic object for AfterUpdate()

    Thanks, Kyle 123. I'm just going to resort to batch error-checking on this one rather than open a new can of worms.

+ 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