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!

Global Variable Question

Status
Not open for further replies.

SGElizabeth

Programmer
Nov 5, 2003
6
US
I have a standard module that declares the app's global variables, including the logon id of the user. I have no problem using the logon variable in a form, but when I try to use it in a report, the report does not find the variable. Why is this? The variable was declared as a public variable in a standard module. Any help would be greatly appreciated.

Thanks.
 
Hi,

I normally use a Global variable, together with a Public Function. I then use the function in the WHERE clause of my SQL and then bind the report or form to that query.

So...

Code:
Public intMyVariable As Integer

Code:
Function MyVariable() As Integer

  MyVariable = intMyVariable

End Function

Then...

Code:
SELECT MyField1... etc
FROM tblMyTable
WHERE MyID = MyVariable()

I've never had any problems using this method, but thats not to say there definitely won't be any, but it's definitely worth a try.

Hope this helps.

Leigh Moore
Solutions 4 MS Office Ltd
 
Thanks for the suggestion. I tried it, and unfortunately the variable is still empty. Argh!! I talked to the original programmer and she told me that for some reason, the value of that variable is sometimes dropped.

 
Use another public variable and use something like this at the assignment juncture to preserve the previous value.

if(!IsEmpty(MyPublicVar))
MyPublicVar2 = MyPublicVar

use MyPublicVar2 in the report.
 
I don't know if you are still having this problem and I don't know why it happens but I do know how to fix it.

I have a similar issue where I declare a PUBLIC variable in code and expect a report to use it. In this case I had copied a report from another project and just modified the report format for the current(new) project. It could not see the PUBLIC variable, I even ran it in debug and looked before, during and after the report and the only place it did not exist was in the report.

However, I then created the report from scratch in the new project and just copied the fields, code, etc. from the one that didn't work to the new one and it could see the PUBLIC variable.

Go figure.

Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top