Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public variables

Status
Not open for further replies.

davidwhite22

IS-IT--Management
Sep 17, 2007
2
US
I have a test program where the 1st form is "pass1"
as shown below:

Option Compare Database
Public num1 As Integer

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
num1 = 11

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "pass2"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub
##################
it sets the variable and opens form "pass2"
form "pass2" sees variable and its value = 11.

If I send this program to other users with access 2002, 2003,2007 "pass2" does not see the variable set in "pass1"

what setting causes this??
thanks
 
I'd suggest setting a breakpoint in the Load event of pass2 and checking the value of num1 on the systems that have this issue. What is the value of num1 on those systems?

Have you considered using OpenArgs instead of a public variable?

DoCmd.OpenForm stDocName, , , , , , num1


dz
 
I am more suprised that you can reference the variable. The variable is a public variable in a class module (the forms module). This variable is only in scope during the life of the form and you need to reference the variable using the forms identifier. In other words it is available to the procedures of the form. Dimension the variable in a standard module and then it will be available to the entire application.
 
First of all, I don't see the point of creating a variable in the first form when you intend using it in the second form!
If you wish to create the variable for the life of the database then use MajP's method (declare it in a module). If you want to keep the variable data after the database has closed and reopened, create a table to store the variable and use dlookup to access the data.

P.S. the table method is also a useful way of storing the database version.


Ian Mayor (UK)
Program Error
Always make your words sweet and nice. Because you never know when you may have to eat them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top