Having trouble using Public Variables please Help (1 Viewer)

Jon123

Registered User.
Local time
Today, 07:08
Joined
Aug 29, 2003
Messages
668
I need to open a form to display a bmp picture. There are several different bmp so they are stored in a table. I have different forms where I want to pull the bmp's from so in order to make the query work I was going to use a couple of Variables in order to do this so that I would not need to create many different forms.
So what I have so far is
module

Option Compare Database
Public MyVariable1 As String
Public MyVariable2 As String

Now on a form I have a command button and in the onclick property I have
Private Sub form1_Click()
MyVariable1 = "value 1"
MyVariable2 = "value 2"
DoCmd.OpenForm "Frmtwo"

now on Frmtwo I have many more command buttons that a user can select which opens other forms and in the Record Source of these other forms I have it set to the query. So in the criteria field on the query I want to have = [MyVariable1] and =[MyVariable2] Now I know this won't work so I need to creat a function to set the variables and then a function to get the variables is this correct? Does anyone have any examples as to how to do this?
thanks for your time
jon
 

MSAccessRookie

AWF VIP
Local time
Today, 07:08
Joined
May 2, 2008
Messages
3,428
I need to open a form to display a bmp picture. There are several different bmp so they are stored in a table. I have different forms where I want to pull the bmp's from so in order to make the query work I was going to use a couple of Variables in order to do this so that I would not need to create many different forms.
So what I have so far is
module

Option Compare Database
Public MyVariable1 As String
Public MyVariable2 As String

Now on a form I have a command button and in the onclick property I have
Private Sub form1_Click()
MyVariable1 = "value 1"
MyVariable2 = "value 2"
DoCmd.OpenForm "Frmtwo"

now on Frmtwo I have many more command buttons that a user can select which opens other forms and in the Record Source of these other forms I have it set to the query. So in the criteria field on the query I want to have = [MyVariable1] and =[MyVariable2] Now I know this won't work so I need to creat a function to set the variables and then a function to get the variables is this correct? Does anyone have any examples as to how to do this?
thanks for your time
jon

Are the Public Declaration statements contained in one of the VB Modules behind one of your forms (Form1, Form2, etc.) or are they in their own separate Module? I believe that they need to be in a separate Module that is not associated with any form. I like to make a separate module for my public declarations.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:08
Joined
Aug 30, 2003
Messages
36,123
Both the variable declarations and this should be in a standard module, not behind a form:

Code:
Public Function GetVariable1() As String
  GetVariable1 = MyVariable1 
End Function
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:08
Joined
Aug 30, 2003
Messages
36,123
I posted that on your other thread.
 

Users who are viewing this thread

Top Bottom