Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Developers    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
global variable for report
Gary Becker 
     
2 years ago
I'm trying to use a global variable for the data on a mailing label. I update the variable with a double-click event on a text box. I want to use the variable so that I can use the same report in multiple places instead of creating many instances of the same report. Maybe there is a better way to do this.
Gary Becker OP  @Reply  
     
2 years ago

Sami Shamma  @Reply  
             
2 years ago
Gary

Show where you define the variable.
Is it in a global module? How do you assign data to it?
How do you read data from it?
Kevin Yip  @Reply  
     
2 years ago
You cannot use a global variable as the control source.  You can, however, use a VBA function as the control source.  See the picture below.  The VBA function used in this manner also cannot contain any VBA elements: e.g., MyFuncton(Forms!Form1!Field1), or MyFunction(GlobalVar).  It can only use literal values in the argument, MyFunction(100), or no argument.  In short, you cannot have any VBA stuff on the property sheet.  VBA code can only be run by a VBA module.  A property sheet cannot run any code, because it is just a storage container of properties.

If you want to "dynamically" assign values to a control, make the control unbound (i.e. blank control source), then use VBA code to assign values to it when needed.
Kevin Yip  @Reply  
     
2 years ago

Kevin Yip  @Reply  
     
2 years ago
Power Apps can do what you try to do: put variables on the property sheet.  When variables change values, so do the properties, automatically, without needing any extra code.  Power Apps is "low code" platform, so it is designed that way.  Access and VBA aren't.
Gary Becker OP  @Reply  
     
2 years ago
I couldn't get the Function() method to work either. The function retrieved the data from the text box fine'I tested that by displaying it with a MsgBox. But putting the function as the control source for the MailingLabel control on the report didn't work. So, on to Plan B. And that was adding a field to my HelperT table, then using SQL to update the field in the table, then using a DLookup as the control source for the MailingLabel control. See attached. This may not be the most elegant solution, but it is working. Thanks for your response!
Gary Becker OP  @Reply  
     
2 years ago

Richard Rost  @Reply  
          
2 years ago
I, like Adam, would use TempVars.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developers.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 8/24/2026 8:24:43 AM. PLT: 0s