Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    May 2003
    Location
    Whittier, California
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Call Sub from Different Form (2003)

    Hello All,

    I've successfully created subs atatched to forms that call other subs on the same form or in other modules. However, I cannot get subs to open subs on a different form. For example, form1 has: Public Sub cmdSendMornEm_Click()

    I try to call it from form2 with this line: Call cmdSendMornEm_Click

    The cmdSendMornEm_Click() sub does not use any arguments. I've tried using "Call" or leaving it out, adding "()" at the end, deleting the "_Click", opening the 1st form first using Do.Cmd Openform, but I keep getting the error message "Compile Error: Sub or Function not Defined". What am I doing wrong?

    Thanks, Kevin

  2. #2
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Call Sub from Different Form (2003)

    Try the following:

    Call Forms.Form1.cmdSendMornEm_Click

    I use a similar line in one of my databases, but not sure if Form1 needs to be open for it to work.

  3. #3
    Lounger
    Join Date
    May 2003
    Location
    Whittier, California
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Call Sub from Different Form (2003)

    Now I get a new, not very helpful error message:

    Error #2465 Application-defined or object-defined error

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Call Sub from Different Form (2003)

    Try
    <code>
    Call Form_Form1.cmdSendMornEm_Click
    </code>
    You can even omit the keyword Call if you prefer. The event procedure cmdSendMornEm_Click MUST be defined as Public.

  5. #5
    Lounger
    Join Date
    May 2003
    Location
    Whittier, California
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Call Sub from Different Form (2003)

    That did the trick. Thanks again, Hans [img]/forums/images/smilies/smile.gif[/img]

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Call Sub from Different Form (2003)

    Sorry I missed your post Kevin, have only just logged back in.

    Glad you sorted your problem though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •