@Pat Hartman First of All, let me thank you for your explanation, your time and your will to help.@KitaYama Shared code doesn't belong in a form's class module. That is what I think you are talking about. If you need to do something that affects data from multiple forms, the best solution is to extract the code to a standard module and pass in a form reference. Then the shared code module gets "data" from whatever form is passed in but it is not trying to run code that lives in some other form. One place I use this is to check security. Every form needs to use this code so it is in a standard module and I call it from the necessary events - BeforeUpdate, BeforeInsert, Open, BeforeDeleteConfirm. I pass an argument. And the shared code tells me if the user is authorised to perform the function I am asking about. The current user is known to the application so the code I am calling knows how to find it and I use the same location for that in all apps (the login form is never closed. It is just hidden so it keeps some data throughout the use of the application) so the code transfers without modification.
Executing code in a stand alone class module is a totally different thing. However, they should still be "black boxes". Each procedure should do only one thing (ie. be highly cohesive) and the arguments passed should be minimal (ie loosely coupled). Even though Forms are class modules, you can only reference objects in them if they are loaded. You might be able to reference code procedures but I would just never do this. Perhaps this is why you are seeing differences. Are you sure the form you are referencing is loaded?
I still wouldn't do it. I would move the common code to a standard module or if you prefer to a class module. The class module will give you the intellisense you are looking for. Just pay attention to coupling and cohesion as you create shared code. Aim for highly cohesive and loosely coupled to avoid cascading problems when code changes are needed.
When I need to share code within a form's class module, I move it out of the event procedure (where I probably originally put it) and move it to a function and call it from the events that need it. I never call an event procedure from any other place in the form's class module. Events fire when they are triggered. No one looking at your code later, including yourself will anticipate multiple uses of that code. That easily leads to code that will break the second use. Why do you think we cringe every time a new version of Access is released? Code changes in one procedure break other uses of that code. When your code is in a stand-alone procedure, it is obvious to all that it is being executed from some other procedure and so you always look for those and make sure that your code is compatible with all changes. I would be especially leary of executing form class module code from outside of the form. No one who follows you is ever going to expect the code in some form's "Current event" to be called from some other form - this is what decades of experience tells me.
But honestly, I think either you didn't read #1 post, or my poor English failed to show my problem.
Let me put it this way.
Forget about everything said and posted above. Just imagine this one is the first post.
There's an attachment here. It contains two forms and one module. Each form has a button(btn) and textbox(txt).
Open either of them. No matter which one.
Click the button.
The code stops at the following function:
Code:
Public Function ClickTest(frm As Access.Form)
Stop
With frm
.txt.SetFocus
.btn.Visible = False
End With
End Function
In the empty line after With frm , type a dot. The intellisense shows form's properties. But you can not find txt (the name of the textbox) or btn (the name of the button) in intellisense. All I need is to find a way the intellisense shows the object names too.
Do you have a method that shows all properties of the form and the objects in that form in intellisense?
@AHeyne I'm sorry but I'm too short in my free time and too busy with my job. I'm still reading and studying Implements to understand your method in depth and find a way not to loose all other forms properties in intellisense. I'll get back to you if I have more questions. Thanks again.