Rabu, 12 Februari 2014

Re: [MS_AccessPros] RE: Holding Global Variables in a Class Module

 

I often combine Public variables with a table and use a wrapper function.  The function checks to see if the variable is set, and if not, it loads it from the table and returns it.  If the variable is set, it simply returns the value and avoids the overhead of loading again.


Public gvarUserName As Variant

Public Function GetUserName() As String

    If IsNull(gvarUserName) Or IsEmpty(gvarUserName) Then
        gvarUserName = DLookup("UserName", "GlobalsTable")
    End If
    GetUserName = gvarUserName
End Function

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Feb 11, 2014, at 11:14 PM, <wrmosca@comcast.net> <wrmosca@comcast.net> wrote:

I don't remember that discussion, but I'll weigh in with what I do.

My users get MDEs or ACCDEs. Those will not lose the variable value when an error happens. Secondly, The problem only comes up when the error is not handled with an error trap.


Liz's idea is a good one but if you go that route why not just use a table. Retrieving the value could be done with a domain aggregate. DLookup("myValue", "myVarTable", "MyVariable = 'UserGroup'")


Regards,

Bill Mosca, Founder - MS_Access_Professionals

http://www.thatlldoit.com

Microsoft Office Access MVP

http://mvp.microsoft.com/en-us/mvp/Bill%20Mosca-35852

My nothing-to-do-with-Access blog

http://wrmosca.wordpress.com




---In MS_Access_Professionals@yahoogroups.com, <zctek@aol.com> wrote:

Hi All,
 
Many months ago there was a discussion re. holding Global Variables in a Class Module being preferable to holding them in a standard Module because in the event of an error, the Variables could lose their value.
 
If that is true then I would like to see and example of a Class Module holding one or more Global Variables.
 
I would appreciate any help. I am using Access 97, 2003, and 2007.
 
Regards, Clive.

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (5)
.

__,_._,___

Tidak ada komentar:

Posting Komentar