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

Close window?

Status
Not open for further replies.

Vcscwi

Programmer
Jan 15, 2004
57
US
Hi,

I have a MS Access 2003 app where in a Login form OnOpen I run a module which defines a public variable. The variable simply holds the user who has just logged into the database.

OnOpen of Login form:
DoCmd.OpenModule "GlobalVar"

GlobalVar Module
Public iUser as String

When I run the DoCmd.OpenModule "GlobalVar" it opens a VBA window and that window stays open. What command can I run to close is so the user doesn't see it?

Thanks!
 
I believe that's the intention/purpose of the OpenModule method of the docmd object.

If this module is a standard module, you don't need to "open" it, just assign the correct value to the public variable (i e - remove the openmodule thingie)

Roy-Vidar
 
Where would be an appropriate place to declare a public variable? I need to be able to see it from various forms.

Thanks
 
Sorry - I cant' say I addressed where to declare public variables, did I?

I just said don't open VBE and the module - see the OpenModule method of the docmd object, is the equivalence of hitting ALT+F11 to enter VBE, and you don't wanna do that during program execution.

What you want to do, is probably just assign a value to the public variable - then do just that - but don't open the VBE...

A public variable - a variable declared with the public keyword in the declaration section of a standard module - is public - there is no need to open the VBE, be it programaticly or through ALT+F11 to assign the value - just assign it, and it will be available as long as the db is open...

Roy-Vidar
 
If I understand correctly... in my "Login" form...

Option Compare Database
Option Explicit
Public iUser As String

If this is correct, it didn't work. As soon as I close the Login form the value is lost.

I'd put it in a temp table but multiple users are logged in at the same time and then will overwrite the value.

I guess I could skip the public variable all together and stuff the value in a dummy field on the "Main menu" as long as that is open I'll be able to reference the value.
I just thought that was a clumsy solution.

Thanks for your help!
 
That is not a standard module, but a forms module - then the variable will only be available as long as the form is open... To craete a public variable you need a standard module

In VBE - Insert | Module

Then do the declaration there

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top