Microsoft KB Archive/198637

= ACC2000: Access Methods That Reset The Visual Basic Project =

Article ID: 198637

Article Last Modified on 12/9/2002

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q198637



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

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



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

You reset your variables with the following methods:

AddFromFile (Module Object)

AddFromFile (References Collection)

AddFromString

AddFromGUID

CreateEventProc

DeleteLines

InsertLine

InsertText

ReplaceLine

Remove (References Collection)



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.



MORE INFORMATION
A database's Visual Basic for Applications project consists of all the standard and class modules stored in the database. When you use one of the methods discussed in the Symptoms section of this article, the project is recompiled. This resets the project state, including any defined variables.

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

Steps to Reproduce Behavior
 Open the sample database Northwind.mdb.  Create a module and type the following lines in the Declarations section: Option Explicit Public pMyVar As String   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   To test this procedure, type the following line in the Immediate Window, and 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.   After the procedure has completed, type the following in the Immediate Window, and press ENTER: ?pMyVar Note that the public variable is reset and now contains an empty string. </li></ol>

<div class="references_section">