Zydeceltico
Registered User.
- Local time
- Today, 02:27
- Joined
- Dec 5, 2017
- Messages
- 843
I guess repetition is good.
Doesn’t hurt.
I guess repetition is good.
I was saying much the same thing but I prefer to make my functions more generic.
So I might have a global/public variable defined in a standard module
E.g. Public lngClientID as Long.
Then in one or more forms set the value
E.g lngClientID = Me.ClientID
Then have a function GetClientID =lngClientID so I can use it in queries.
Public Function GetInspId() as Long
if currentProject.allforms("SomeFormName").isloaded then
GetInspId = forms("SomeFormName").InspectionEventID.value
end if
end function
Code:the nice thing about that is that you can open the query even if the form is not loaded without getting an error.[/QUOTE] That would be a nice change of pace. :rolleyes:
Code:Public Function GetInspId() as Long if currentProject.allforms("SomeFormName").isloaded then GetInspId = forms("SomeFormName").InspectionEventID.value end if end function
If I wanted to use that inside of the function you've suggested above would the syntax look like this:
GetInspID = Forms(strFormName).InspectionEventID.Value
OR like this:
GetInspID = Forms!strFormName.InspectionEventID.Value
… can't tell if it's understood that a variable declared as Public in a form module isn't available to any other form or report.
Forms!formname.publicvariablename
The first one can use a string variable. The second one won't work as the form name is an integral part of expression.
BTW You can leave off Value as it is the default property of the control.
Must be a version thing then. I putPublic variables are available to other forms and reports. They are exposed as members of the object. Like any other member they just need the reference qualified.
Code:Forms!formname.publicvariablename
The general module gets loaded the first time that anything in it gets referenced - even if the first thing is a function or subroutine. At the point of module "load" you will have automatic instantiation of all variables, public or private, in that module at their default values. Which means the numerics become 0, the strings become "", the objects become Nothing, and the the variants become Null.
Dim x As Variant
? IsNull(x) ' returns False
? IsEmpty(x) ' returns True
The default scope of a module level variable in an object module is Private.Must be a version thing then. I put
Option Compare Database
Option Explicit
Dim pubPublic As Variant
Not 100% sure, but I think variables are what are "instantiated" (Dim'd) and when they are assigned a value or object they are "initialized". I also think that some would argue that to instantiate is to create a class because of the jargon of other programming languages, so who knows for sure.
what I'm reading here leads me to think otherwise, at least for Access. He seems to make the distinction between "declaring" and "initializing".I think Initialized means that they are allocated memory,
re the variable thing - I see what I missed. Never tried that in all my years as I've always considered it to be less than desirable practice.