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
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » 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.
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.
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”?
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
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.
You can call code from a form module if it is declared as Public, for example
Public Sub lbl2_Click()
instead of
Private Sub lbl2_Click()
You would call it from another module like this:
Call Form_frmMain.lbl2_Click
To call a Public procedure from a standard module (the kind you create by clicking New in the Modules section of the database window), you don’t have to specify the name of the module, just the name of the procedure:
Call MyProc
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.