Variable for use anywhere

Lanason

Registered User.
Local time
Today, 20:02
Joined
Sep 12, 2003
Messages
258
Hi Guys,

a little help needed please.

I have a database with forms and buttons on the forms - within each button I Dim items and use them just in that button.
i.e DIM x as string

but I want to set a variable when I first open and use it on any form and any button. The variable will be the 'username'

what is the syntax to DIM this variable so that I can just use it when whenever and wherever. :banghead:
 
Have you tried searching the vba help files for "Declaring Variables"?
 
Declare a global variable in a standard module as-
Public gstrUserName As String

The variable will be available to all forms. You can assign a value to this variable when a user logs in, which can be done in a login form if you have one or you can assign a value at any stage that suits your application.
 
Have you tried searching the vba help files for "Declaring Variables"?

Just tried searching for that and with the help of a few threads / posts I have got it working. Even worked out how to display the Variable on the form :D:D:D
 
Hi Guys,

my line in the openform property me.Text8.Value = GBL_FullName works great and it displays the content of the variable in the form BUT

the same thing does not work in an openreport property ???
I get runtime error 2448
"you cant asign a value to this object"

Any ideas why?
 
Try it in the On Format event of the reports Detail Section.
 
Just tried searching for that and with the help of a few threads / posts I have got it working. Even worked out how to display the Variable on the form :D:D:D


Dear Lanason,

Would you mind telling me which thread/posts that helped you to get it working?
I have the same problem with you.
I've already declare the variable in declaration area above the procedures:

Code:
 Public MyLoginId As Long
And I've already assign the value to the variable in the procedures:

Code:
 MyLoginId = Me.cboEmployee.Value
MyLoginId is the variable
Me.cboEmployee.Value
is a combo box where the user may choose their names
I'm intend to use the values assigned in MyLoginId variable in every other procedurs
But it only available in the module where the code written, but it seems not working in any other module.

Code:
  DoCmd.RunSQL "INSERT INTO tbUserLog (LogDate, UserNum) VALUES (now(), " & MyLoginId & ")"
Please help. Thank you.

Regards,
Jerry
 
Jerrysim

Have you declared the variable in a General Module. It won't work if you have declared it in the module of a form.
 
Ouww, I did declared it in the form module.
Thank you Mr. Bob Fitz
I should search the general module then.
 
Just put:
Code:
Public MyLoginId As Long
in any general module, below the lines:
Code:
Option Compare Database
Option Explicit
 

Users who are viewing this thread

Back
Top Bottom