ACC2000: Access Methods That Reset The Visual Basic ProjectID: Q198637
|
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)
These methods automatically reset the database's Visual Basic for Applications project.
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.
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: Following the steps in this example will modify the sample
database Northwind.mdb. You may want to back up the Northwind.mdb file
and perform these steps on a copy of the database.
Option Explicit
Public pMyVar As String
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
CreateNewProc
Note that a form is created with an event procedure, followed by a
message box that contains the contents of the public variable.
?pMyVar
Note that the public variable is reset and now contains an empty string.For more information about these methods, in the Visual Basic Editor, click
Microsoft Visual Basic Help on the Help menu, type "the name of the method" in
the Office Assistant or the Answer Wizard, and then click Search to
view the topic.
For more information about class modules, in the Visual Basic Editor, click
Microsoft Visual Basic Help on the Help menu, type "class modules, overview" in
the Office Assistant or the Answer Wizard, and then click Search to
view the topic.
For more information about library databases, in the Visual Basic Editor, click
Microsoft Visual Basic Help on the Help menu, type "library databases" in
the Office Assistant or the Answer Wizard, and then click Search to
view the topic.
Additional query words: prb global public variables scope
Keywords : MdlProb PgmObj
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: July 15, 1999