Go Back   Access World Forums > Microsoft Access Discussion > Queries

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 12-03-2008, 12:55 PM   #1
Jon123
Newly Registered User
 
Join Date: Aug 2003
Location: CT
Posts: 668
Thanks: 11
Thanked 1 Time in 1 Post
Jon123
Having trouble using Public Variables please Help

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

Jon123 is offline   Reply With Quote
Old 12-03-2008, 01:01 PM   #2
MSAccessRookie
AWF VIP
 
MSAccessRookie's Avatar
 
Join Date: May 2008
Location: Central NJ, USA
Posts: 3,428
Thanks: 13
Thanked 127 Times in 122 Posts
MSAccessRookie is a jewel in the rough MSAccessRookie is a jewel in the rough MSAccessRookie is a jewel in the rough
Re: Having trouble using Public Variables please Help

Quote:
Originally Posted by Jon123 View Post
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.
__________________
No one is expected to know everything and we can all learn from each other if we try.

This forum is about taking the next step (or perhaps the next two steps) toward becoming a better Access programmer, and the AWF Forum Members will help you on your journey.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
MSAccessRookie is offline   Reply With Quote
Old 12-03-2008, 01:01 PM   #3
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 32,160
Thanks: 10
Thanked 3,886 Times in 3,829 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: Having trouble using Public Variables please Help

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

__________________
Paul
Microsoft Access MVP

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Old 12-03-2008, 02:00 PM   #4
Jon123
Newly Registered User
 
Join Date: Aug 2003
Location: CT
Posts: 668
Thanks: 11
Thanked 1 Time in 1 Post
Jon123
Re: Having trouble using Public Variables please Help

so how do I call that function?
Jon123 is offline   Reply With Quote
Old 12-03-2008, 02:03 PM   #5
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 32,160
Thanks: 10
Thanked 3,886 Times in 3,829 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: Having trouble using Public Variables please Help

I posted that on your other thread.

__________________
Paul
Microsoft Access MVP

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading public variables Bakta Modules & VBA 1 05-10-2005 04:55 AM
How to tell RDBMS opened by ODBC connection? Schof Modules & VBA 3 08-22-2004 06:16 PM
Public Variables and Queries (or 2 forms, 1 query) Kylep Queries 0 07-12-2004 01:21 PM
Public Variables ListO Modules & VBA 10 02-25-2004 02:34 AM




All times are GMT -8. The time now is 06:19 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World