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

how to set & read global?

Status
Not open for further replies.

hblabonte

Programmer
Oct 3, 2001
84
US
I know this seems like a simple item, but I'm not sure how to do this.

I have one form, and upon reading the record, I want to set a "global" field for the ApplicationType (on the event). In another event (applicationType before update), I want to read the global variable to see if it is not empty. In other words, before a user changes a selection in the drop down, I need to check if there was a value there previously.

My ideas/code to date:

In a Module...
Public AppType As String

In the Form...
Private Sub Form_Current()
AppType = Forms!FrmServiceRecord!Application
End Sub

In the same form, I need to check the variable which was set above.

Private Sub Application_BeforeUpdate(Cancel As Integer)
If AppType ...blah blah
End Sub

I know that I'm not setting the global properly, as my check shows the field as blank. Can someone point me in the right direction?

thanks in advance!
 
If I need to make absolutely sure a global has maximum scope I declare the global and then create two procedures all in the same module like this:

Public AppType

Public Function SetApptype(byval strData AS STRING)

Apptype=strData

End function

Public Function GetApptype() as String
GetAppType=AppType
End Function


In the form you would then
Call SetAppType(Forms!FrmServiceRecord!Application)

To retrieve it in any control anywhere in the app
=GetAppType in the control source

It's a little overkill but it guarantees no scoping bugs



 
Scoping can be confusing but try making the reference explicit - Module1.AppType - and see if that helps.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top