Solved Calling a module inside a Form_Load event

Romio_1968

Member
Local time
Today, 10:40
Joined
Jan 11, 2023
Messages
126
I have the following module>

' Hide the controls with Tag "H"

Option Compare Database
Option Explicit

Public Sub HideTaggedH(frm As Form)
Dim ctl As Control
For Each ctl In frm.Controls
If TypeName(ctl) = "SubForm" Then
If ctl.Tag = "H" Then
ctl.Visible = False
End If
ElseIf ctl.Tag = "H" Then
ctl.Visible = False
End If
Next ctl
End Sub

I am calling it from inside Form_Load event, using

Call HideTagedH(Me)

The form options are>
Option Compare Database
Option Explicit

This pops a compile error. Expected variable or procedure, not module.
What am I doing wrong here?
 
When it pops the compile error, there usually is a highlighted line. What is it?

Other than failing to use code tags and indentation, I see nothing particularly wrong with the Sub, at least at first glance. If those were cut/paste cases, though, you have a spelling mismatch between what you called and what you declared. If you simply typed them in, I hope the mismatch is just a typo.

However, if you repeated the Option Compare Database in the body of the form's class module, it would look to the compiler that you were declaring a new module within another module. Normally, those two option lines can ONLY go ONCE in the general declaration area of a module, whether it is a general module or a class module.
 
HideTaggedH is a procedure in a code module.
Is the code module possibly also called 'HideTagedH'?
Rename the code module and your code will run.
Use Call ProcedureName or Call ModuleName.ProcedureName
Module name and procedure name must be different.
 
Last edited:
Check your spelling of HideTaggedH vs HideTagedH
 
HideTaggedH ist procedure in a code module.
Is the code module possibly also called 'HideTagedH'?
Rename the code module and your code will run.
Use Call ProcedureName or Call ModuleName.ProcedureName
Module name and procedure name must be different.
I renamed the module HideControlTaggedH
I kept the same Public Sub name HideControlTaggedH
noe the Call HideTagedH(Me) pops a different compile error: Sub or function not defined
 
Tip to avoid typing errors: write the procedure name in lower case only and use IntelliSense*, if the name is automatically corrected to the correct spelling afterwards, the name is spelled correctly.

*) Use IntelliSense: write the first few characters and then type Ctrl+Space ... the name will then be automatically complemented or suitable matches will be offered as a selection.
 
An even easier way is to type the module name. You always know the module name since it is visible in the object explorer. Intellisense will bring up all the procedures so you can select from the list and get it correct every time.
 

Users who are viewing this thread

Back
Top Bottom