+ Reply to Thread
Results 1 to 9 of 9

Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

  1. #1
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

    I am not sure how to refer to an Object in my sub

    Please Login or Register  to view this content.
    Normally if I didn't need to use the object when I clicked enter I'd call my form by

    Please Login or Register  to view this content.
    However if I leave out the frm_Name As Object I get the error 'Argument Not Optional' when I use the frm_Name in cmd_Enter_Click.

    So my question is what do I need to do to use an Object in the Sub cmd_Enter_Click()?

    As always thanks for helping me.

    EDIT: FOR CLARITY, VBA won't take the parameter but I need a parameter or I can't use the object.
    Last edited by 111StepsAhead; 06-02-2011 at 12:16 AM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

    Hi 111StepsAhead try this at the beginning of your sub:
    Please Login or Register  to view this content.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

    I get the compiler error "Procedure declaration does not match description of event or procedure having the same name."

    I am not very familiar with passing by Reference in VBA. Any other suggestions here?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

    Is this the click event for a button on a form? If so, it doesn't take any arguments.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

    Yes, it is a click event for a button on a form. If it is true that it doesn't take any arguments then do I need two forms in this case?

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

    I don't understand why you can't just refer to the object the way you normally would.
    Remember what the dormouse said
    Feed your head

  7. #7
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

    Hold up! How would I normally refer to the object?

    My issue is I have two processes that do the same thing. They both call a first form to select the mode. Based on what process is used a different user form will be called after the mode is chosen.

    i.e. I have 3 modes. If I pick mode 1 certain options will appear but because either process might have been chosen I need frm_Name.

    I will get back to this in a bit. Taking a short break.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

    You can't change the signature of event handlers, and as Romper says, there's no need to.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Using an object in a Sub cmd_Enter_Click(frm_Name As Object)

    Depending on flow:
    If the first form calls the second, then pass a variable from the calling procedure so ti knows what to load.
    If the calling procedure calls the second object after the mode is chosen (possibly better) then the first procedure can determine what to load.

+ 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