Solved

control array

Posted on 1998-10-22
7
167 Views
Last Modified: 2010-04-30
Still seeking answers. This is what I've come up with so far.

Using a separate Command click:
     Sub Command1_click()
        dim d as integer
        for d = 1 to buttons
          unload imgX(d)
          buttons = buttons - 1
        next d
    end sub

  if I try to call this routine, without clicking the command button I get an error. I have also tried to immediately unload the control array element after creating it and get the same error as below.

      call routine code
           command1.setfocus
           sendkeys "%C", true

I get this error:

     unable to unload in this context

Is there a way to use a call procedure without the user actually clicking on the command button to get the control array to clear. So when a combo box selection is used the control array is recreated.

0
Comment
Question by:MaryD
  • 4
  • 3
7 Comments
 
LVL 2

Accepted Solution

by:
BergJC earned 50 total points
ID: 1441139
MaryD,
     Just place the code in your command click event into a function inside a code module. Then you can call it from wherever you want.

0
 
LVL 2

Expert Comment

by:BergJC
ID: 1441140
For example:

Inside a code module, have this:
     Sub UnloadArray()
            dim d as integer
            for d = 1 to buttons
              unload imgX(d)
              buttons = buttons - 1
            next d
      End sub

Then you can just call this sub from anywhere in your program.
0
 

Author Comment

by:MaryD
ID: 1441141
BergJC,

I tried putting this code into

1. as a function
       function UnloadArray()
       .
       end function
       received same error
2. as a sub routine in a module - ModMain.bas
       public sub UnloadArray()
       .
       end sub
       received compiler error that the control array was not
       recognized
3. the command_click still works even though nothing else does

What did you mean by code module? Any of the above?

This doesn't make any sense how the command_click works but the
others do not.!!!!


0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 2

Expert Comment

by:BergJC
ID: 1441142
Did you put the form name in front of the control array when you were referencing them?

For instance,
     
2. as a sub routine in a module - ModMain.bas
      public Sub UnloadArray()
          dim d as integer
          for d = 1 to buttons
              unload form1.imgX(d)
              buttons = buttons - 1
          next d
       end Sub

0
 
LVL 2

Expert Comment

by:BergJC
ID: 1441143
In order to reference the control array from a module, you must also place the form name in front of the control object.
0
 

Author Comment

by:MaryD
ID: 1441144
I placed the form name in front of the imgX(d) in the module, it now recognizes the control array, but unfortunately I still get
the error: "Unable to unload in this context"

We are running VB6 if this makes a difference.
0
 

Author Comment

by:MaryD
ID: 1441145
thanks for your help
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

778 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