SparklySpartan
New member
- Local time
- Today, 11:51
- Joined
- Feb 25, 2025
- Messages
- 25
Hi everyone,
I learned that I can use two methods to access controls on other forms from outside their respective modules. I was curious if one or the other is considered best practice so I decided to pick the brains of the community here.
I should preface that with either approach, I always ensure the form I will by trying to reference is loaded and if not design the code to handle it gracefully.
The first way I learned to do this was the "!" approach. For example, here's how I can access the control called "Project_Menu" on the main form:
I recently discovered this can also be accomplished by referencing the name of the VBA module for that form
I believe this is a superior way of doing it, because I have access to autocorrect for all of the controls on the form "Main_f" and autocorrect for the properties of those controls. Whereas with the "!" approach I get no autocorrect at all.
I was wondering which is considered better practice. Is there anything that can be done with the "!" method that can't be done with my new preferred method?
I know this might be a silly question but I'm genuinely curious, so thanks for indulging me on this one.
I learned that I can use two methods to access controls on other forms from outside their respective modules. I was curious if one or the other is considered best practice so I decided to pick the brains of the community here.
I should preface that with either approach, I always ensure the form I will by trying to reference is loaded and if not design the code to handle it gracefully.
The first way I learned to do this was the "!" approach. For example, here's how I can access the control called "Project_Menu" on the main form:
Code:
Forms!Main_f!Project_Menu
I recently discovered this can also be accomplished by referencing the name of the VBA module for that form
Code:
Form_Main_f.Project_Menu
I believe this is a superior way of doing it, because I have access to autocorrect for all of the controls on the form "Main_f" and autocorrect for the properties of those controls. Whereas with the "!" approach I get no autocorrect at all.
I was wondering which is considered better practice. Is there anything that can be done with the "!" method that can't be done with my new preferred method?
I know this might be a silly question but I'm genuinely curious, so thanks for indulging me on this one.