Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Procedure call (new) (VBA)

    Is it possible to call a procedure in a different user form? I and selecting a button in one form and would like to run a procedure in another form.

    Thanks,
    Nick

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

    Re: Procedure call (new) (VBA)

    The procedure in the other userform must have been declared as public, not as private. Say that you have a userform frmTest, with a public procedure MyProc. You can call it from another userform as

    frmTest.MyProc

    or

    Call frmTest.MyProc

    Note: MyProc can be an event procedure, such as the On Click procedure of a control. Event procedures are Private by default, but you can change them to Public manually.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Procedure call (new) (VBA)

    i did as you said, but i am getting an error. it says object required. here is my code:
    Private Sub btnInc_Click()
    frmCalendar.lblWK38_Click
    End Sub

    thanks

  4. #4
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Procedure call (new) (VBA)

    And i did make the procedure public. i forgot to mention that

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

    Re: Procedure call (new) (VBA)

    a) Is the other form named frmCalendar ? (Spelling must be exact)
    [img]/forums/images/smilies/cool.gif[/img] Is the label's name lblWK38 ? (Idem)
    c) Have you made lblWK38_Click public?

  6. #6
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Procedure call (new) (VBA)

    1. Yes
    2. Yes
    3. Yes

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

    Re: Procedure call (new) (VBA)

    Should work then... In which Office application are you doing this (Word, Excel, ...), and which version (97, 2000, ...)?

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Procedure call (new) (VBA)

    Hi,
    Is the called userform in the same workbook as the calling userform?
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Procedure call (new) (VBA)

    It is in Access 2003. I will try to explain the problem better.

    I have a main form with procedures on it. When one of the individual forms is up, I have a button the move to the next form. Then next form is also accessible by an on click event of the main form. I want when I hit the next button on the individual forms to move to the next on click procedure.

    Thanks again for your help.

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

    Re: Procedure call (new) (VBA)

    It's a pity that you didn't make it clear that you were using Access at the outset. Forms in Access are quite different from userforms in Word, Excel etc.

    I'm afraid I don't understand your description. What do you mean by "a main form with procedures on it"? Which "individual forms" do you mean? What is "the next on click procedure"?

  11. #11
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Procedure call (new) (VBA)

    I apologize for not making that clear.
    I have a timesheet database that has a yearly calendar as the startup form. Each week has an on_click event to load the correct form. When a user clicks on a week number, a different form is pulled up for that particular week for users to input there weekly hours. If a user wants to go to a different week, they can either return to the calendar form to select a different week number or select the next button on the weekly form. When the next button is selected, I want to call the procedure on the yearly calendar form which pulls up the next weeks form. In this case it will be the next weeks form to input their hours to.
    I hope this clears things up.
    Thanks

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

    Re: Procedure call (new) (VBA)

    Do you mean that you have created a separate form for each week of the year?

  13. #13
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Procedure call (new) (VBA)

    Yes, I know this was a poor way to design this database, but it was in this shape when i took over working on it.

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

    Re: Procedure call (new) (VBA)

    Yuck! One form should be enough. I think it would be worthwhile to redesign the database, it'll probably save you time in the end. With a single form, it would be easy to move to the next or any other week.

  15. #15
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Procedure call (new) (VBA)

    I am posting a example of what I am wanting to do and maybe this will help to clarify my problem. When the database loads, you will see two labels on the frmMain. The top label "Test1" will pull up another form, "frmOne". On frmOne there is a button that when I push it, I want to execute the on_click procedure for the second label on the frmMain. I hope this will help.

    P.S. I redesigned the database to use one form instead of 52. The size of the database decreased by almost 75%. Thanks for the advice.

Page 1 of 2 12 LastLast

Posting Permissions

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