Call public variable

mithani

Registered User.
Local time
Tomorrow, 08:22
Joined
May 11, 2007
Messages
291
Hi mates

I am moving my head arround but couldn't figure it out. What I am looking for is when I enter user name in my login form, should save in public variable so I can call in any other form or can save in any table.

Thanks for your help

Mithani
 
In a standard module (not the form's module; make a new module if needed) insert this line:

Code:
Public MyPublicVariableNameHere As String

If it's in your form's module, you still can make it public, but you have to use form's name, e.g.:

Code:
debug.print Forms!MyFormName.MyPublicVariable

Which is quite awkward, and hence the suggestion to use a standard module to avoid the lengthy referencing.
 
Thanks Banana,

Still its showing #Name? I am using Access 2007

Any clue? If you got sample form, please send thru to me.

Regards

Ameer
 
Did you set the login textbox's control source to that public variable? If so, that's not right way to do it.

Rather, make that textbox a unbound control (e.g. deleting the control source and leaving it blank), then in the properties, under Event tab, select "AfterUpdate", and select "[Event Procedure]", then click that tiny button on right.

In the editor window, insert this line after the line "Private Sub xxx_AfterUpdate()":

Code:
MyPublicVariable = Me.MyTextBoxName

This sets the public variable to whatever was typed in the textbox.
 
Dear

Do I have to write this code to call public variable value?

debug.print Forms!frmDatabaseLogon.PublicUserID

Regards

Mithani
 
Only if that public variable is in the form module, which I did not recommend.
 
I ve tried and tried but think am not good in Access. If you got any sample DB, please send thru.

Thanks a lot

Mithani
 

Users who are viewing this thread

Back
Top Bottom