Setting Variable/Constant

Capilano

Registered User.
Local time
Today, 14:55
Joined
Feb 19, 2001
Messages
63
I have a main form in which almost all of my subforms are 'nested' in. In almost all of my Modules, I am having to re-declare the following in each and every procedure:

Dim frm As Form_frmOneWindow
Set frm = Forms("frmOneWindow")

I have tried experimenting making this a Constant but the Set frm... never seems to comply. Is there anyway I can declare this at the top of the Module (underneath Option Compare Database and Option Explicit statements) and make it Public for the entire Module? Otherwise, I find that I am declaring and emptying within each procedure. What a waste...there must be a better way.

Thanks in advance

Pat
 
Rather than using Dim, use Public instead.

Public frm As Form_frmOneWindow

You'll also need to move the Public statement to the top of your code, i.e. outside any procedure.

[This message has been edited by PearlGI (edited 12-13-2001).]
 
My email system has just crashed, so I'll have to answer your question here. (It's also useful to keep all questions and answers on the forum, that way when people do a forum search on a topic they then get the full answer
smile.gif
)

Anyway, in your original post you state that 'I find that I am declaring and emptying within each procedure'.

How (and why) are you emptying [frm] in each procedure? Maybe that's the key to your problem!

I'm off home now, but I'll check for any re-posts tomorrow.

HTH
Darren
 
I followed your instructions and placed the 'Dim' portion of statement at the top of the Module and made it public.

Option Compare Database
Option Explicit
Public frm As Form_frmOneWindow

This worked but I am still
having to re-declare the 'Set' statement in each procedure of the Module.

Function TypicalFunction()
Set frm = Forms("frmOneWindow")
'Blah!
'Blah!
'Blah!
Set frm = Nothing
End Function

My question is... Is there another method of declaring the Set frm statement publically in the Module so that I don't have to do it in each and every procedure within the Module. (Similar to what you advised me on the Public frm As Form_frmOneWindow)

By the way, I have read in several publications that acknowledge that while the 'Set' portion of the procedure 'dies' when the procedure ends, it is still prudent to formally close or undeclare it so as to free up the memory footprint in a similar fashion as one would close an open recordset or empty a variable.

rec.close
db.close
strTypicalVariable = Empty

Any suggestions?

Thanks very much

Pat
 
You've hit the nail on the head in your last paragraph!!

You're 'undeclaring' [frm] at the end of each procedure by using {Set frm = Nothing
}. That's why you're having to redeclare it at the start of each procedure.

While I agree it's prudent to conserve memory by freeing up declared objects, you only need to do this for locally declared objects at the end of each procedure.

For those objects you have declared as [Public], you only want to 'undeclare' them once you've finished with them. Therefore remove all of the {Set frm = Nothing
} from your procedures apart from the one at the point where your module finally terminates.
 

Users who are viewing this thread

Back
Top Bottom