ACC97: Access Methods That Reset The Visual Basic Project

Last reviewed: September 29, 1997
Article ID: Q173004
The information in this article applies to:
  • Microsoft Access 97
  • Microsoft Visual Basic for Applications

SYMPTOMS

Advanced: Requires expert coding, interoperability, and multiuser skills.

When you use certain Access methods that modify modules or references, all variables in the same Visual Basic for Applications project are reset.

You will reset your variables with the following methods:

AddFromFile (Module Object) AddFromFile (References Collection) AddFromString AddFromGUID CreateEventProc DeleteLines InsertLine InsertText ReplaceLine Remove (References Collection)

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access 97" manual.

CAUSE

These methods automatically reset the database's Visual Basic for Applications project.

RESOLUTION

Move any variables that you do not want to be reset to an add-in or library database. Add-ins and library databases have separate Visual Basic for Applications projects; therefore, variables stored in them are not affected when you use one of these methods.

STATUS

This behavior is by design.

MORE INFORMATION

A database's Visual Basic for Applications project consists of all the standard and class modules stored in the database. When you one of these methods, the project is recompiled. This resets the project state, including any defined variables.

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.

  2. Create a module and type the following lines in the Declarations section:

           Option Explicit
           Public pMyVar As String
    

  3. Type the following procedure:

         Sub CreateNewProc()
    
            Dim frm As Form
            Dim mdl As Module
            Dim ret As Long
    
            ' Set Public Variable.
            pMyVar = "Hello"
    
            ' Create a new form.
            Set frm = CreateForm()
            Set mdl = frm.Module
    
            ' Create an event procedure in the form's
            ' module.
            ret = mdl.CreateEventProc("Load", "Form")
    
            'Display current contents of Public variable.
            MsgBox "pMyVar = " & pMyVar
         End Sub
    
    

  4. To test this procedure, type the following line in the Debug window, and then press ENTER:

           CreateNewProc
    

    Note that a form is created with an event procedure, followed by a message box that contains the contents of the public variable.

  5. After the procedure has completed, type the following in the Debug window, and then press ENTER:

           ?pMyVar
    

    Note that the public variable is reset and now contains an empty string.

REFERENCES

For more information about these methods, search the Help Index for the method name or ask the Microsoft Access 97 Office Assistant.

For more information about class modules, search the Help Index for "class modules, overview," or ask the Microsoft Access 97 Office Assistant.

For more information about library databases, search the Help Index for "library databases," or ask the Microsoft Access 97 Office Assistant.

For more information about creating add-ins, please refer to "Building Applications with Microsoft Access 97," Chapter 17, "Creating Wizards, Builders, and Menu Add-Ins," pages 455-480.


Additional query words: prb global public variables scope
Keywords : MdlProb PgmObj
Version : WINDOWS:97
Platform : WINDOWS
Hardware : x86
Issue type : kbprb
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.