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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Each and Forms Collection

Status
Not open for further replies.

gwinn7

Programmer
Feb 10, 2001
1,004
US
Related to my problem from yesterday, I have the following function launched from a macro...

Public Function DebugFormNames()

Dim F As Form

For Each F In Application.Forms
Debug.Print F.Name
Next F

Debug.Print Forms.Count

End Function

This function was a test to confirm that all forms that I opened are indeed open and programmatically accessible. However, I get an error that breaks on the "Next F" line. This error is

Run-Time Error '40036' Application defined or object error.

Any ideas anyone? Can anyone reproduce this?

Gary
gwinn7
 
The code works fine on my machine.

Maybe you need to check the reference.

Seaport
 
Try taking the "F" off the NEXT. It is not required. It is probably a bug but it appears that "F" is being referenced after the last "F" has been processed. I believe "F" is NOTHING after the end of FORMS.
 
Interesting! Yes, I also checked my references prior to submitting the thread. Still looking for a solution though.

Thanks for the feedback thus far!

Gary
gwinn7
 
Here is some new information. If open the forms through the user interface, then no error. If I open the forms via code, then the error occurs.

Gary
gwinn7
 
Gary -

I'd venture to guess that something else is going on somewhere in your application that's causing this. Have tried the code in several applications and it appears to work fine. The 'Next F' issue (not sure whether I agree with this) doesn't seem to have any effect, nor does opening the form from interface versus code.

Have you tried using the code in a different application on your machine? If it works in one but not another, then, to me, this would be further evidence that something within the application is causing the problem.

Do you perhaps have code that is modifying the forms collection? If so, it could be something as simple as refreshing the collection before moving on.

Keep us advised.

Bob
 
Here is a more detailed overview of the situation. I am using a master form that opens 4 other forms. The 'Visible' property for these forms are set to false until they are needed.

These forms cascade, much like a wizard. The user clicks 'open next', then the visible property of the next form is set to true while the current form is set to false. The user can traverse each form until finished.

The problem originally was when I tried to create custom properties and access these public properties. This is when the errors started to occur, but I should be able to do this if I make these properties public (I have done it before!).

When tried to access one of the 4 forms in the Debug window, the error occured again. When I tried to simply display the name of the form, the error occured. However, I could display all of the remaining 3 forms' name. WEIRD!!! Anyhow, I hope this provides some extra insight. I will be working on this some more.

Thanks again!

Gary
gwinn7
 
Hi Gary,
Ran fine here for me Access 2000 on 2000Pro. It compiles, and even with visible false is fine.
I'd guess you might have to back up a little and undo the custom properties step by step until you find the one that's causing you the grief. :) Gord
ghubbell@total.net
 
Actually, I have since removed all the custom properties. Still the problem persists. Well, I guess I am down to uninstalling and reinstalling Access. I will still investigate this more.

Gary
gwinn7
 
Gary-

Think you've provided your own solution. Suspect you're going to find your problem somewhere within this statement:

"The problem originally was when I tried to create custom properties and access these public properties. This is when the errors started to occur, but I should be able to do this if I make these properties public (I have done it before!)."

The operative phrase is: "...but I should be able to do this if I make these properties public (I have done it before!)."

Please keep us advised.

Bob

 
Nope, no solution. Like I said, I removed the properties. They are no longer there. Therefore the problem does not seem to be with the custom properties. In other words, I really don't have a clue why this problem is occuring.

I know I can access properties any how because its been done before without incident.

Gary
gwinn7
 
I was able to create a model Access app that should have reproduced the problem. I could not reproduce the error on a different machine (Progress! :) ) .

The problem appears to be one of two items. One, something is wrong with the Access/Office installation (unlikely) on the original machine. Or second, I may have overlooked a spelling error of a property, variable, or an object in my original application. As soon as I know for sure, I will post the resolution.

Once again, thank you for your time on this.

Gary
gwinn7
 
OK, here is the solution:

Apparently, when there is a compile problem with one of the forms, then that form will not be accessible in the Forms collection programmatically. This means no control, property, or method exposed publicly can be accessible. A run-time error '40036' results when attempted.

The wierd thing about this is, is that I did compile the application and the problem was not detected. Yikes!

The solution is when you see this symptom, then there is probably a syntactical problem within that particular form.

Issue resolved. Hopefully, this will spare others from considerable frustration.

Gary
gwinn7
 
Thanks Gary...dag nab Access Gremlins.... ;-) Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top