Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Global Status Fn < Ctrl-A Select Long Text | Open Last Customer >
Back to Global Status Fn    Comments List
Pinned    Upload Images   Link   Email  
Transcript
Richard Rost 
           
15 days ago
Welcome to another TechHelp video brought to you by AccessLearningZone.com. I'm your instructor, Richard Rost. Today, we're going to cover something that I get asked all the time. For those of you familiar with my videos, I have this thing called a status box. It's built into my TechHelp free template, which is a free database that I use in most of my TechHelp videos. It's simply a big box where you can send messages to it. I have just a button here that says "Hello World." You can use it for displaying variables or giving the user messages. It's basically a replacement for a message box that pops up in your face and you have to hit OK. This will allow execution to keep going yet give you a track record of what's going on. It's kind of like a Debug.Print, but it works in runtime.

A lot of people ask me if they can use this from other places, like if they open up the customer form. Can they have this thing send messages there? Sure, and that's what we're going to cover in today's video. I'm going to show you how to make the status function global, so it will work from anywhere in your database. Any form can use it, and any bit of VBA code can use it. Of course, you'll still need to be able to see it. Don't cover it up. Make sure that this form opens up where it can be seen. Then you can use it from anywhere in the database.

First, some prerequisites. This is a developer-level video, but I'm going to take it nice and slow. So this is kind of like a beginner developer video. First off, if you haven't watched my Intro to VBA video, go watch it first. It'll teach you everything you need to know to get started in about 20 minutes. Watch my initial Status Box video. It teaches you how to set up the status box. In this one, I show you how to put a status box on multiple forms. You can put a unique status box on every form if you want to, but today we're going to make it so they all use the same box. Also, watch my Variable Scope and Visibility video. This explains what a global variable is. It's a variable you can use from anywhere in the database, not just the form that you're on. This is important. Go watch this video too. These are all free videos. They're on my YouTube channel and on my website. Then come on back.

The first thing we have to do is go into Design View here. Let's go into the code for our button and right-click Build Event. That'll bring up our Code Builder. Now in here, this is the form module. This is the module that's built into the form main menu F. Here is my Private Sub Status. This means that only this form can call this subroutine because it's private. So we're going to move this to a global module. I'm going to just cut that out. Get rid of the extra spaces there. Then I'm going to come over here and I'm going to go down to my Global Module. If you don't have a global module, there's one built into the TechHelp free template called Global Module. If you don't have one, you can create your own. Go to Create and then Module, and that'll do the same thing. Don't use a class module. Use a regular module. I have a whole separate video on that. In the Global Module, I have a sleep subroutine that allows you to make the system wait for a second or two. We're going to just put this right on top of that.

Right here, we're saying Private Sub Status. Now we don't want it to be private because if it's private, only this module will be able to use it. So we're going to change this to Public. Now everybody in the database, every form, every report, every other module can see this Status subroutine. So now it has scope and visibility. The entire database can use it. The first thing we do is we send in S as a string. That's the message we want to put in the box. That's fine. Here's a problem though. Do a debug compile and it says "Variable not defined." It has no idea what Status Box is.

Status Box is a text box on this form, but in order to use it here, not on that form, we have to call it by its full name, which is Forms!MainMenuF!StatusBox. We had to do it here, and we also have to do it there. It's going to say Forms!MainMenuF!StatusBox equals S, whatever we send into it and a new line. Then the rest of the Status Box, so it just adds this on top. Now if we Debug Compile, we get away with it. It seems to work.

If you're not familiar with that naming convention, go watch this video. This is what I call an expert-level video. It's not quite up to the developer yet. I assume you already know this. If you don't, go watch this video.

At this point, if I come back over here and I hit my button, let's say this stuff, I hit my button, it still works. This button is calling Status, but Status is now in here. Status knows to use this box. Now, if I go to a different form, let's say I want to put a button on this form to do the same thing. I just copy one of these buttons, copy-paste. I'll right-click Build Event. Yes, I know you should give your button a good name, but this is just a test, so Command 30 is fine. Here I'm going to say Status "Hello from the Customer form." Same thing. Once in a while, File Save All. Back out here, let's close it, open it, and hit the Hello button. There it goes. You can see it in the background.

You could force this menu form to come to the foreground if you want to, but I personally find that kind of annoying. I'll show you how to do it though. In the Status function itself, right-click Go to Definition. That'll bring you right to it.

You could open the form by saying DoCmd.OpenForm "MainMenuF". Then what that'll do is it'll open the form, which if it's not open, will open it for you, which could be a problem and won't generate an error message. It also has the secondary effect of putting it in the foreground. If you are going to issue messages or bring it to the foreground, you might want the users to see it.

That's it. Pretty straightforward today. Lots of people ask me this, so I figured I'd make a video about it. That's what I make videos on, the things people ask me the most. That's going to be your TechHelp video for today. I hope you learned something. Live long and prosper, my friends. I'll see you next time.

TOPICS:
Creating a global status function in VBA  
Changing module scope from Private to Public  
Handling undefined variables in global functions  
Using fully qualified name for form controls  
Copying buttons and assigning events in forms  
Bringing a form to the foreground with DoCmd  
Debugging and compiling in VBA  
Using Global Module for shared functions

COMMERCIAL:
In today's video, you will learn how to make your status box function global within an Access database. We will show you how to transform it from a simple form-specific message display to a universal feature accessible by any form or module. You will see how to move the status subroutine from a private module to a global one to enhance visibility and scope across your database. We will guide you through adjusting the naming conventions to ensure seamless functionality. Whether you want messages displayed from different forms or need the main menu to pop into the foreground, you'll get all the insights here. You'll find the complete video on my YouTube channel and on my website at the link shown. Live long and prosper my friends.
Add a Reply Upload an Image

 
 
 

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 2025 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 1/23/2025 11:03:26 AM. PLT: 1s