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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PUBLIC variable not working 1

Status
Not open for further replies.

FoxProProgrammer

Programmer
Apr 26, 2002
967
US
My form has a subform. The user can click in a field on the subform and change the contents. The following events run.

The Enter event stores the initial value of the field.

The AfterUpdate event checks if the user changed the contents of the field.

The code works with the following exception. The value of chgSaved is not available to procedures in the main form's module. I use chgSaved to determine whether to display a MsgBox when the user closes the Form. If unsaved changes exist, the message warns them that they will lose their changes unless they click Yes to continue editing.

Code:
Private Sub PartSN_Enter()

initSN = PartSN.Value

End Sub


Private Sub PartSN_AfterUpdate()

If initSN <> PartSN.Value Then
    Forms!frm_EditJob.btn_save.Enabled = True
    chgSaved = False
End If

End Sub

The variable chgSaved is declared below the Option Compare Database statement in the main form's module. My recollection is that this is the area where public (global) variables are defined.

Code:
Public chgSaved As Boolean

The Access Help says:

Variables declared using the Public statement are available to all procedures in all modules in all applications unless Option Private Module is in effect;

Option Private Module is not in effect. Why is the value of chgSaved not global? It is global for all procedures in the Main form's module. It just doesn't work on the subform.

Thanks!


dz
 
By the way, I know that I could create a hidden field on the main form to store chgSaved. I would prefer to use a global variable if possible.

Thanks,


dz
 
The access help talked about Public variables declared in a standard code module.
For Public variables declared in a form's class module you may simply reference them as a property of the form:
Forms![name of mainform].chgSaved

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top