+ Reply to Thread
Results 1 to 6 of 6

Calling a sub from a different userform

  1. #1
    Registered User
    Join Date
    11-22-2012
    Location
    United States
    MS-Off Ver
    Office 2013
    Posts
    25

    Calling a sub from a different userform

    Hi All,

    I'm having trouble with a userform calling subs.

    In Userform1:

    Private sub CommandSubmit_Click()
    SubmitForm.Show
    End Sub
    This shows userform2 which lets the user confirm submission or cancel to go back. When the submit button is clicked:

    Private Sub CommandSubmit_Click()
    Call SubmitDataTrue_Change
    End Sub
    This calls a sub from the code of userform1, but if I test and click submit, I get an error "compile error sub or function not defined"

    I hope this is enough info. Thanks for the help in advance!
    Last edited by domnisignis18; 07-04-2013 at 09:25 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Calling a sub from a different userform

    All Subs in userforms are declared as Private by default, as you can see in the code you posted.

    That means that they are out of scope to other subs and can't be called from them.

    Why do you want to call the other userform's change event?

    That's kind of unusual.

    PS Can you use code tags when posting code? Makes it easier to read and copy.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-22-2012
    Location
    United States
    MS-Off Ver
    Office 2013
    Posts
    25

    Re: Calling a sub from a different userform

    It's really more out of ignorance than anything else. I just learned VBA recently. I've already tried changing the sub to
    Please Login or Register  to view this content.
    but the error remained.

    The second userform serves as a pop up prompting a user to check the data before submitting to a protected workbook as they cannot access the worksheet itself. There are probably better ways to accomplish this for all I know.

    As for
    Please Login or Register  to view this content.
    I don't know if I even needed the
    Please Login or Register  to view this content.
    event as part of the sub.

    Any suggestions?

    Thanks!

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Sorry, I'm a little confused.

    Why do you want to call the sub in the other userform?

    What does it do?

    Can whatever it does only be done in that sub?

  5. #5
    Registered User
    Join Date
    11-22-2012
    Location
    United States
    MS-Off Ver
    Office 2013
    Posts
    25

    Re: Calling a sub from a different userform

    Changed to a
    Please Login or Register  to view this content.
    Thanks for the help though. I knew I was going about it in a roundabout way.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Mmm, still confused and not sure how I 'helped'.

    But, hey if you've found a solution that's the important thing.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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