Error when accessing Public var in form - TechRepublic
General discussion
January 26, 2005 at 02:26 PM
dwlassen

Error when accessing Public var in form

by dwlassen . Updated 21 years, 5 months ago

Hi,

Here is an issue that is haunting the heck out of me. I am working with MS Access 2002 forms in which I am looking to reference a public variable in the code snippet of a form control, but the problem is that the variable is always shown as when I put a breakpoint in the snippet code and view the variable.

Let me give a step by step example:

1) Create a new database

2) Open the VBA editor, add a new Module “Module1”

3) In the new module, add the following line:
“Public xPublicVar As String”

4) Create a new form with 2 fields (fld1 and fld2)

5) Right-click the “fld1” control, select Properties, then the Event tab. In the “After Update” event field, create a section of VBA code like this:
xPublicVar= “xyz”
Flag this line for breakpoint in the debugger
Close the VBA editor

6) Right-click the “fld2” control, select Properties, then the Event tab. In the “After Update” event field, create a section of VBA code like this:
“x=1”
Flag this line for breakpoint in the debugger
Close the VBA editor

7) Run the form

8) Enter a value into “fld1”, hit enter

9) The debugger appears and the program stops at the line: xPublicVar= “xyz”. Run this line of code by pressing F8, then Add Watch for xPublicVar, the value will show “xyz” as expected

10) Remove the breakpoint in the fld1 code

11) Run the form, enter a value into fld1, hit Enter, enter a value iun fld2, hit Enter. The VBA debugger will now open at the “x=1” line in the fld2 code snippet. Add a Watch for xPublicVar. The value “xyz” now does NOT appear, instead the value appears as ““.

Could someone please help me understand what I am missing to have the Public Variable available in the fld2 code snippet?

Thanks in advance,

Dennis

This discussion is locked

All Comments