Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Ctrl Collection - procedures outside of form - error 2467

Status
Not open for further replies.

arpeggione

Programmer
Nov 23, 2005
99
US
Hi: I originally had a set of procedures within a form working well for a custom collection of controls with tags. The controls all have the tag "Contract". When I move all of my procedures from the form to a module, I get the error 2467 (Application-defined or object-defined error). Any ideas? This may be some kind of declaration error. Note, I always use Option Explicit...

thank you in advance! Karen

procedures below:

The collection is:

Public mcolGroupContracts As New Collection

>I initialize the collection on form load by calling the procedure below:

Public Sub InitializeCollections()
Dim ctl As Control

If mcolGroupContracts.Count = 0 Then
For Each ctl In Me.Controls
If ctl.Tag = "Contract" Then
mcolGroupContracts.Add ctl, ctl.Name
End If
Next ctl
Set ctl = Nothing
End If
End Sub

>procedure is called from a secondary procedure in module
Call ShowControls(mcolGroupContracts, False)

>procedure itself (showing where it bombs)
Public Sub ShowControls(mcol As Collection, bolshow As Boolean)
MsgBox "Hello Show Controls"
Dim ctl As Control

MsgBox "SC1"
>procedure bombs out somewhere in here....
For Each ctl In mcol

MsgBox "ctl.name = " & ctl.Name

ctl.Visible = bolshow
Next ctl
MsgBox "SC2"

Set ctl = Nothing
End Sub
 
It looks OK to me so I tested it. It worked fine. Put the code in a standard module like you said. Is it possible the form is closed when you call it?
 
How are ya arpeggione . . .

You moved your code from a class module (code behind the form) to a standard module. [blue]Me[/blue] is used to reference the form in a class module. In a standard module you have to use a [blue]form object[/blue] for proper reference. It would like:
Code:
[blue]   Dim frm As Form, ctl As Control
   
   Set frm = Forms![[purple][b]YourFormName[/b][/purple]][/blue]
Then replace [blue]Me[/blue] with [blue]frm[/blue] throughout the routine.

Note: [purple]YourFormName[/purple] has to be open at the time the code runs or you'll get an error.

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Aceman1: I see what you're saying - oops! i didn't notice the "me" in there and forgot to change it. Thank you for finding that. i am at home and will try tomorrow, but that is undoubtably the problem.

thank you and cheers!

karen
 
Well Aceman1....unfortunately....I checked - and the procedure "InitializeCollections" (the one with the "me" in it) is in the form. So..thats not it...

any other ideas? Anyone?

thanks again for all of your time!

Karen
 
And...MajP...I call these procedures from a button on the form, so the form should be open....

thanks again, Karen
 
To whom it may concern: I solved the problem! I got rid of the collection object and used almost the same procedures (and tags) without by just calling the following procedure:

It works and is pretty speedy. If anyone has any comments to add - they are always appreciated. Karen

Public Sub ShowContracts()
Dim ctl As Control

If myECARContractsFlag = True Then Exit Sub

For Each ctl In Forms!frmEditCARs2011!subfrmEditCARLogCtnr.Controls
If InStr(1, ctl.Tag, "Contract") > 0 Then
ctl.Visible = True
End If
Next ctl

myECARContractsFlag = True

Set ctl = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top