G
Guest
I am trying to use a public variable in Access 2003 to pass a string from one
form to another. To keep things simple, I've created 2 test forms to
demonstrate the problem.
First form (frmSetName) has the following code:
Option Compare Database
Option Explicit
Public gstrName
'
Private Sub cmdSetName_Click()
gstrName = "John Doe"
MsgBox "gstrName has been set to " & gstrName
DoCmd.OpenForm "frmGetName"
End Sub
Second form (frmGetName) has the following code:
'
Option Compare Database
Option Explicit
'
Private Sub cmdGetName_Click()
MsgBox gstrName
End Sub
Problem: When I click the cmdSetName button in the first form, the public
variable is assigned the value "John Doe", the variable's value is displayed
in the message box, then the second form is opened. When I click the
cmdGetName button in the second form, however, the message "variable not
defined" appears.
Aren't Public variables supposed to be available to all modules?
Can anyone help?
Thanks, Christine
form to another. To keep things simple, I've created 2 test forms to
demonstrate the problem.
First form (frmSetName) has the following code:
Option Compare Database
Option Explicit
Public gstrName
'
Private Sub cmdSetName_Click()
gstrName = "John Doe"
MsgBox "gstrName has been set to " & gstrName
DoCmd.OpenForm "frmGetName"
End Sub
Second form (frmGetName) has the following code:
'
Option Compare Database
Option Explicit
'
Private Sub cmdGetName_Click()
MsgBox gstrName
End Sub
Problem: When I click the cmdSetName button in the first form, the public
variable is assigned the value "John Doe", the variable's value is displayed
in the message box, then the second form is opened. When I click the
cmdGetName button in the second form, however, the message "variable not
defined" appears.
Aren't Public variables supposed to be available to all modules?
Can anyone help?
Thanks, Christine