+ Reply to Thread
Results 1 to 8 of 8

Userforms: Run same code when enter any textbox

  1. #1
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Question Userforms: Run same code when enter any textbox

    Hi There,

    i have 15 textboxes in my userform (all with tags).

    instead of having 15 seperate sub routines that call on one macro is there a way i can write some code that, on entering any texbox within a form, a specific routine would be called

    i tried using the Userform_click sub like so, but with no joy:

    Please Login or Register  to view this content.
    i appreciate any help on this

    thansk for reading and for any help offered

    cheers
    Last edited by Macdave_19; 12-16-2009 at 08:51 AM.
    Mr MaGoo
    Magoo.Inc MMVII

    If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userforms: Run same code when enter any textbox

    Put the code into a Procedure in the Form module

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Question Re: Userforms: Run same code when enter any textbox

    Hi Roy,

    yeah i know i can do that but that evaids the point of my question lol.

    basically i'm trying to avioid writing the below for each textbox:

    Please Login or Register  to view this content.
    i'm looking for a snippet that on entering anytextbox within a form can call a specific macro, is this possible? in the end i'm merely trying to tidy up the code behind it all.

    cheers for you swift original reply though

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userforms: Run same code when enter any textbox

    maybe you could adapt the Class module used in my Calendar Form

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Userforms: Run same code when enter any textbox

    Normally I would say use a class, but that won't work for the Enter event of a textbox unfortunately, so I think you are out of luck.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userforms: Run same code when enter any textbox

    That answers my suggestion

  7. #7
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Question Re: Userforms: Run same code when enter any textbox

    How do you know a class module wouldn't work for the Enter event of a textbox? and also what event's would it work for!

    cheers guys

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Userforms: Run same code when enter any textbox

    Quote Originally Posted by Macdave_19 View Post
    How do you know a class module wouldn't work for the Enter event of a textbox?
    because I'm clever?
    and also what event's would it work for!
    BeforeDragOver
    BeforeDropOrPaste
    Change
    DblClick
    DropButtonClick
    Error
    KeyDown
    KeyPress
    KeyUp
    MouseDown
    MouseMove
    MouseUp


    basically every event that isn't inherited from the base Control class (and unfortunately although you can declare an MSForms.Control variable WithEvents, which would give you the Enter event, you can't then assign your actual control to the variable!)
    Last edited by romperstomper; 12-16-2009 at 08:52 AM. Reason: Correction of last statement.

+ 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