+ Reply to Thread
Results 1 to 4 of 4

Calling sub routines

  1. #1
    Andrew
    Guest

    Calling sub routines

    I have a userform with a sub-routine "under" it that I want to call from a routine under another userform within the same project. I changed the called routine title from Sub to Public Sub having read some of the previous posts on a similar topic but I seem to be missing the plot somewhere.

    UserForm1
    Private Sub cmdPrint_Click()
    Call Print_Report

    Public Sub Print_Report()

    ...... this works


    UserForm2
    Private Sub cmdPrint_Click()
    Call Print_Report

    ...... this doesn't work

    I cant put the Print_Report() routine in the Modules section because it pulls values from the forms. I guess there is a way to get over that problem as well but I thought the first fix would be the easiest to discuss.

    Thanks for your help in advance.
    Andrew



  2. #2
    Bob Phillips
    Guest

    Re: Calling sub routines

    Call Userform1.Print_Report

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Andrew" <[email protected]> wrote in message news:[email protected]...
    I have a userform with a sub-routine "under" it that I want to call from a routine under another userform within the same project. I changed the called routine title from Sub to Public Sub having read some of the previous posts on a similar topic but I seem to be missing the plot somewhere.

    UserForm1
    Private Sub cmdPrint_Click()
    Call Print_Report

    Public Sub Print_Report()

    ..... this works


    UserForm2
    Private Sub cmdPrint_Click()
    Call Print_Report

    ..... this doesn't work

    I cant put the Print_Report() routine in the Modules section because it pulls values from the forms. I guess there is a way to get over that problem as well but I thought the first fix would be the easiest to discuss.

    Thanks for your help in advance.
    Andrew



  3. #3
    Tom Ogilvy
    Guest

    Re: Calling sub routines

    You can put the Print_Report code in a general module

    You should probably alter it to receive a reference to the form calling it
    as an argument

    then it can pick up the values it needs from the form

    UserForm1
    Private Sub CmdPrint_Click()
    Print_Report Me
    End Sub
    ---------------------------
    UserForm2
    Private Sub CmdPrint_Click()
    Print_Report Me
    End Sub
    ---------------------------
    General module
    Public Sub Print_Report(form)
    MsgBox form.Label1.Caption
    End Sub


    --
    Regards,
    Tom Ogilvy


    "Andrew" <[email protected]> wrote in message
    news:[email protected]...
    I have a userform with a sub-routine "under" it that I want to call from a
    routine under another userform within the same project. I changed the
    called routine title from Sub to Public Sub having read some of the previous
    posts on a similar topic but I seem to be missing the plot somewhere.

    UserForm1
    Private Sub cmdPrint_Click()
    Call Print_Report

    Public Sub Print_Report()

    ...... this works


    UserForm2
    Private Sub cmdPrint_Click()
    Call Print_Report

    ...... this doesn't work

    I cant put the Print_Report() routine in the Modules section because it
    pulls values from the forms. I guess there is a way to get over that
    problem as well but I thought the first fix would be the easiest to discuss.

    Thanks for your help in advance.
    Andrew




  4. #4
    Andrew
    Guest

    Re: Calling sub routines

    Thanks a lot gents.

    "Bob Phillips" <[email protected]> wrote in message news:%[email protected]...
    Call Userform1.Print_Report

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Andrew" <[email protected]> wrote in message news:[email protected]...
    I have a userform with a sub-routine "under" it that I want to call from a routine under another userform within the same project. I changed the called routine title from Sub to Public Sub having read some of the previous posts on a similar topic but I seem to be missing the plot somewhere.

    UserForm1
    Private Sub cmdPrint_Click()
    Call Print_Report

    Public Sub Print_Report()

    ..... this works


    UserForm2
    Private Sub cmdPrint_Click()
    Call Print_Report

    ..... this doesn't work

    I cant put the Print_Report() routine in the Modules section because it pulls values from the forms. I guess there is a way to get over that problem as well but I thought the first fix would be the easiest to discuss.

    Thanks for your help in advance.
    Andrew



+ 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