scope

CData
3StarLounger
Posts: 308
Joined: 24 Dec 2015, 16:41

scope

Post by CData »

hi again,
a scope question in an access application .accdb;

in module: Global Constants
is: Public mRegion as string

in form1: in a Private sub there is code where a value is provided mRegion = "QA"

in form2 in the OnOpen Event I can test with message box that mRegion = QA

all seems well but in a command button OnClick event in form2 it tests with a message box that mRegion =
[blank]

why is the scope of this variable good at the object's OnOpen event but not on a command button's click event?

CData
3StarLounger
Posts: 308
Joined: 24 Dec 2015, 16:41

Re: scope

Post by CData »

ah - have answered my own question

the OnClick event has old/existing code at the top of the stack that Dims a variety of variables - and one of those was mRegion
essentially resetting it.....

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: scope

Post by HansV »

I was just going to ask about something like that. Good that you found it!
Best wishes,
Hans