473,396 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can't pass global variable value to Access query

I've read a hodgepodge of suggestions all over the internet for passing global variable info to Access queries but can't make it work for me.

I'm using ACCESS 2010. I have a form with 3 subforms. The subforms are almost identical and each has a button which should open a report. I want to have one report based on one query which receives its criteria based on which of the 3 buttons is pressed.

Here is what I've cobbled together from the various internet searches....

Expand|Select|Wrap|Line Numbers
  1. ' I create the public variable in a module by itself
  2.  
  3. Public EmplID As String
  4.  
  5. ' Next I ensure I got the global variable value and open a query.  You'll see that the report is inactive.  Eventually I'll take the MsgBox and query out of the code and just open the report but for now, the query is the problem.
  6.  
  7. Private Sub Command41_Click()
  8.  
  9. MsgBox "global variable " & (EmplID)
  10.  
  11. DoCmd.OpenQuery ("Q_JB_OfferLtr2")
  12.  
  13. 'DoCmd.OpenReport ("R_JB_Job_Offer2"), acViewPreview
  14. End Sub
  15.  
  16. ' Then I try to pass the variable to the ACCESS query.  On the criteria line I use:
  17.  
  18.  = EmplID()
  19.  
  20. ' And I get error 3270, saying "Property not found"
  21.  
  22.  
This one problem has held me up for hours. I'd appreciate any help you guys can provide!
Feb 9 '16 #1

✓ answered by mbizup

You have two options...

1. Use a "Wrapper Function"

Expand|Select|Wrap|Line Numbers
  1. Public Function GetEmpID() as String
  2.    GetEmpID = EmplID 
  3. End Function
  4.  
and call the wrapper function from your query:

Expand|Select|Wrap|Line Numbers
  1. = GetEmpID 

2. OR if your database is in .accdb format, use TempVars:
TempVars

Tempvars, can be used anywhere in your database... queries, property sheets, code, etc...

3 3815
mbizup
80 64KB
You have two options...

1. Use a "Wrapper Function"

Expand|Select|Wrap|Line Numbers
  1. Public Function GetEmpID() as String
  2.    GetEmpID = EmplID 
  3. End Function
  4.  
and call the wrapper function from your query:

Expand|Select|Wrap|Line Numbers
  1. = GetEmpID 

2. OR if your database is in .accdb format, use TempVars:
TempVars

Tempvars, can be used anywhere in your database... queries, property sheets, code, etc...
Feb 9 '16 #2
I still didn't get the global variable to work. I assume it's just a syntax problem but.....

However, I tried the TempVars option (first time I ever heard of it) and was able to make that work. I'm thrilled to get over the first of what I'm sure will be many hurdles!

Thanks mbizup!
Feb 9 '16 #3
mbizup
80 64KB
>>> I assume it's just a syntax problem but.....

Did you try the wrapper function (it has to be a function, not a Sub)? Bottom line is you can only use global variables in VBA. For queries, property sheets, etc you need to get at your globals indirectly, by calling a function which returns their value (and the Module that contains the function cannot have the same name as the function, otherwise you'll get an 'Ambiguous Name' error).

All that said, TempVars are a wonderful tool in accdb databases, and I'm glad you've got it working!
Feb 9 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: sbligh | last post by:
I have a dts that is copying data from one database to another. Relatively simple query to transform the data: SELECT @PayEndDate AS Pay_Ending_Date, GridCode as Grid_Code, Name as...
1
by: Bruce Lawrence | last post by:
I have a textbox on a form that I want to use to display a public variable. How would I go about doing this? Could I use a label as well?
1
by: crjunk | last post by:
I've got an aspx page that allows the user to select different options whenever they want to run a report. On this page, I have added an additional text box for the user to enter in comments about...
19
MSeda
by: MSeda | last post by:
I would like to use a Global variable as a criteria in an access query. in my first attempt to do so I wrote a Function that looks like this Public Function GloVar(ByVal VarName) As String ...
7
by: Stephenoja | last post by:
Hello guys I have a database with three tables each containing the following fields, AccountNo, CustomerName, Table2003,Table2004, Table2005. I would like to make a query that will produce the...
2
by: rahulhere | last post by:
send some example how we increment a global variable value som few functions
2
by: rafficabdullah | last post by:
I need to get input from user and search in the database in shell scrpit I have given the code below how to pass the value of varialbe Count to that query . I have bolded the variable since idont...
1
by: a1lostnomad | last post by:
Hi, I'm JavaScript challenged so I'm going to need some help on this one.... I'm trying to get this accordion (based on prototype/scriptaculous) to open up a panel later in the page. In the head...
17
by: akshay01 | last post by:
Hi all, I am retrieving some rows from DataBase using for loop in jsp and displaying it in a table format.In the output table I am also adding one more text box and checkbok with each row. In text...
1
by: Tom Murphy | last post by:
I want to enter a url of the form "http://www...../index.htm?MC001" and pass the "MC001" to a query string. The query string I have now is: qry = "SELECT QRID, QRContent FROM " & tablename & WHERE...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.