View Single Post
 
Old 11-23-2020, 09:34 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Rekent/Charles,

I'm confused as to what you fellows are trying/actually tried to do:
"My experience, tonight, disagrees. Perhaps I am just tired. I tried setting the value of a public variable declared outside a procedure and it blanked when I ran the second procedure trying to access that value."


Remember the ThisDocument.Module of the VB Project is a Special Class Object module (not a standard module).

If you have this code in a VB Project ThisDocument Module:
Code:
Option Explicit
Public p_strPublicTest As String
Sub Document_Open()
  p_strPublicTest = "Testing one, two, theee ..."
End Sub
You can test it in the ThisDocument module using:
Code:
Sub Test()
  MsgBox p_strPublicTest
End Sub
and in a standard module using:

Code:
Option Explicit
Sub Test()
  MsgBox ThisDocument.p_strPublicTest  'This is the public property of the ThisDocument Class
End Sub
If you have this code in as Standard module:

Code:
Option Explicit
Public Const PublicTest = "Test Constant"
Public p_strPublicTest As String

Sub AutoOpen()
  p_strPublicTest = "Testing one, two, three ..."
End Sub
You can test it in that module, another standard module, a userform class module, the this document module, or any other class associated with the project using:

Code:
Sub test()
  MsgBox PublicTest
  MsgBox p_strPublicTest
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 11-23-2020 at 12:18 PM.
Reply With Quote