Solved Calling a module inside a Form_Load event (1 Viewer)

Romio_1968

Member
Local time
Today, 09:55
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?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:55
Joined
Feb 28, 2001
Messages
27,186
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.
 

Josef P.

Well-known member
Local time
Today, 08:55
Joined
Feb 2, 2023
Messages
826
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:

jdraw

Super Moderator
Staff member
Local time
Today, 02:55
Joined
Jan 23, 2006
Messages
15,379
Check your spelling of HideTaggedH vs HideTagedH
 

Romio_1968

Member
Local time
Today, 09:55
Joined
Jan 11, 2023
Messages
126
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
 

Josef P.

Well-known member
Local time
Today, 08:55
Joined
Feb 2, 2023
Messages
826
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:55
Joined
May 21, 2018
Messages
8,529
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

Top Bottom