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!

Referencing form variables from a function

Status
Not open for further replies.

scoobey

Technical User
Sep 18, 2001
32
GB
Hi All

I am trying to reference a glabal form variable from a function, but for some reason it doesn't seem to work.
On the form, I have a call to run a validation function as follows:

If var_ChangeHasOccurred = True Then Call CheckChanges(Form.Name)

The form name should be sent to the function (which it is). In the function, I need to set the variable 'var_ChangeHasOccurred' to false. A scaled down version of my function looks something like this:

Public Function CheckChanges(FrmName)
Forms(FrmName).var_ChangeHasOccurred = False
'<do something else here>
End Function

The only problem is when I try to set the variable to false in the function, it displays an error saying Access cannot find a field called 'var_ChangeHasOccurred'. I've tried the '.' and '!' symbols but neither work.
The same also happens when I try to set the form dirty to false in the fucntion: Forms(FrmName).dirty = false

Any ideas? Thanks!
 
Public Function CheckChanges(FrmName as form)
FrmName.var_ChangeHasOccurred = False
'<do something else here>
End Function

Then call it like this:
If var_ChangeHasOccurred = True Then Call CheckChanges(me)
 
Hi!

Have you declared 'var_ChangeHasOccurred' in the General Declarations section with the key work Public? If so, you should be able to access it from anywhere in the application. Of course, the form in question must be open.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
How about....

If var_ChangeHasOccurred = True Then var_ChangeHasOccurred = Call CheckChanges(Form.Name)

Public Function CheckChanges(FrmName) As Boolean
CheckChanges = False
'<do something else here>
End Function


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top