Solved

How to create a local Collection in Access 2000 form code

Posted on 2001-06-14
8
147 Views
Last Modified: 2010-05-02
In an Access 2000 Form,
I've got a number of text fields on the form that I want to either hide or unhide (in groups) depending on use selection. What I thought I would do is:
- Declare some collections for the normal grouping of these fields and add the fields to the appropriate collections
- If I need to .visible=false any of the groups I could use a :
           For each x in coll
                    .visible=false
          next x
 
  To hide/unhide the groups.

MY PROBLEM IS:
I cannot find a way to add the textfields to the collections without having to invoke a procedure (because I want them to be always part of the collection, not just after I run a procedure (because I may not always run a procedure before needing the collection)).

How do I add elements to a collection object outside the scope of any procedure?
0
Comment
Question by:Sparrow1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 4

Expert Comment

by:beckingh
ID: 6192208
Declare the Collection with module/global scope.  So outside of any procedure.

Then in your form_load event add the fields to the collection.
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6192223
Form1.frm:

'****************************
Public moColl as Collection

Private Sub Form_Load()
  set moColl = new Collection

  moColl.Add Text1

End Sub

Private Sub Form_Unload()
  Set moColl = Nothing

End Sub
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6192224
Form1.frm:

'****************************
Public moColl as Collection

Private Sub Form_Load()
  set moColl = new Collection

  moColl.Add Text1

End Sub

Private Sub Form_Unload()
  Set moColl = Nothing

End Sub
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Sparrow1
ID: 6192233
So I have to add the fields to the collection inside of a method? I can't do like a static add or such?
0
 

Author Comment

by:Sparrow1
ID: 6192297
Also, if I have to use procedures, should I use Load/Unload, Activate/DeActivate or Open/Close?
0
 
LVL 4

Accepted Solution

by:
beckingh earned 150 total points
ID: 6192314
I'd use Load/Unload.  Guaranteed to only happen once, and before and after (respectively) most everything else.

No way to do a static add to a collection.

But this is pretty standard coding practice.  Write yourself a function to do the add, and call it from the load event.
0
 

Author Comment

by:Sparrow1
ID: 6192564
Thank you very much for your prompt response and continued support. Your answers were exactly what I was looking for.
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6193060
No trouble at all.  Glad I could help.
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question