Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Immediate Window < Numbered Form Items | Toggle Close Button >
Back to Immediate    Comments List
Pinned    Upload Images   @Reply   Bookmark    Link   Email  
Transcript
Richard Rost 
          
3 months ago
Welcome to another TechHelp video brought to you by AccessLearningZone.com. I'm your instructor, Richard Rost. Today we're going to talk about the immediate window, and how you can use it to debug, test, and issue quick commands directly into the VBA editor in your Microsoft Access Database.

Today's video comes from a comment from Sandra from Norfolk, Arkansas, one of my platinum members and handbook editor. She does a great job. She posted this in my captain's log this morning. I ran a YouTube search for immediate window, and nothing came up for Access LearningZone. Oh no, we can't have that. That's my number one goal right now. If you search for anything on YouTube or in Google and one of my videos doesn't show up, I want to know about it. And she's right. I haven't done a video specifically on the immediate window. I have covered it in my developer course, and we'll talk about that at the end of class. But let's learn about the immediate window real quick.

Now this is for developer level users. So if you're not a developer level user and you want to be, here's where you start: Intro to VBA. It's about 20 minutes long. It'll teach you everything you need to know to get started. And go watch my video on error handling as well, because a lot of what you use the immediate window for is for debugging and checking errors and stuff. So go watch this video too. These are both free. They're on my YouTube channel. They're on my website. Go watch those and come on back.

So where is the immediate window? It's actually more of a pane. You can make it a window. I'll show you how. You go to design view, go to your code (any code). I got buttons up here to open up the code editor. If you've watched any of my previous videos, you know this. But any code now down here, you can see I already have it open.

Normally you don't see it, and you don't see the project explorer. So this is what you get by default. They're up here on the view menu. You go to view and then immediate window, and it's right down here. And it's actually a pane and not a window. You can make it a window, right-click on it and go dockable. And now it's a window. It's a full-sized window. You can click on that little buddy there to make it a normal window with the rest of these guys. But I think it works better as a pane. So right-click and then dockable and stick it back down at the bottom. I'll maximize all these guys.

So here's the immediate. We'll call it the immediate window, even though it's a pane right now. You can also press Control G. I don't know if it's on there. Yeah, Control G. I never remember all these shortcuts. I was doing a shortcut a week before, but you get to the point where you only remember really the ones that you use on a regular basis. So if you use it, remember it. There it is. If not, I always go view immediate window.

So what's it good for? Well, let's say you got a little loop here in this button. That's a hello world button. A little for loop. Let's say we're going to dim X as long. We're going to say for X equals 1 to 100 and then next. Now, if you don't want to print it out anywhere, you can use debug.print. And that will print the value to the immediate window. Usually, there's some other stuff going on in here. Other stuff. You're updating records, or you're displaying something, or you're playing sounds, or whatever. Who knows? But in here, we can just say debug.print X. And that will send the output of that value to the immediate window. Ready?

Now, I'm going to have to move these side by side so you can see them at the same time. So we're going to do this, and we're going to resize this guy like so. Close that. And then save changes. Yes, we've moved that over there. All right, let's open that guy back up again and hit the button. Ready? Go. And there it is. See, there's all your output, and they're all in there. Trust me.

So you can use this to display messages. Now I have my little status box. So for something like this, if I'm debugging, I can just go status, you know, the value is whatever. Oops. All right. And then hit the button, and it displays in here. That's something I built. But you can use debug.print if you want, if you don't want to have my little status box. And yeah, everybody always asks me about the status box. I'll put a link to this video down below too if you want to learn how I built this.

All right, let's clear the text down here. I'm just going to click down here, hit Control A, and then hit delete. It's basically like a little version of notepad. You can just treat it like that. Control A to select everything, Control X to cut, delete, whatever you want to do.

Now in addition to getting output, you can also use it to do input. You can actually ask it questions like what's today's date. Start with a question mark and then say date, open close parentheses, and it'll run it through the date function. See that? That's pretty cool. Or you can use it like a little calculator. You could say question mark. What is 5 times 8? Enter. There's 40. Okay. You can use it with known functions to see what something's going to look like. Like, let's say a UCS. UCS and then Richard like that, and I'll convert it to uppercase. That's what the UCS function, any known function you can run through there. So if you want to test it here before actually putting it in your code, you can.

If you have a function you developed a little more advanced, I'm going to go to my global module here. And I'm going to come down here and make my own little function. Like function return X times 2. Let's call it X. I just call it X2. So you'll take an X as a long. Okay. And then we'll say in here return X2 equals X times 2. So whatever number I send into it, it's going to double it, basically. Okay. So now I'll come down here and I'll say what is return X2 of 15. Boom. It returns a 30. See? Here are your own functions in here as well without having to, yeah, you can make a button and do it and click on it. But this gives you a nice quick easy way to verify functions you're working on and make sure they're returning a value.

If you want to use one of your own subroutines like my status function, all the status function does is it takes whatever you send into it and it puts it in this box here. Okay. If you want to run a subroutine, not get a value from a function, then just get rid of the question mark. I'm going to say status. You'll even get the IntelliSense in here. Hi there. And then watch the status box over here when I press on it. Ready? There it goes. See? It ran the status function with S and did all that. Okay. So you can run subroutines and you can query functions in here.

You can also directly manipulate objects and variables. So the name of this box here is status box, and it's sitting on the main menu. So watch this. I can say forms main menu F status box equals high. Just like that. Ready? Boom. See, it set the value for me. Okay.

And you can also query those objects too. So if I get rid of that and put a question mark in front of this, I can query the value of that box. It's high. See? It goes both ways.

Going back to that example we had before, which was this one. For X equals 1 to 100, do some stuff and then print X. If I click that button, okay. What happens if in the middle of this you want to query the value? Let's say I put a breakpoint on that. Okay. And if you don't know what breakpoints are, you can set a point so that when you're stepping through, when you're running the code, you can then step through it. Still more advanced. I got a whole separate video on how breakpoints work. But basically when you run this now, execution is going to stop here. See how it's yellow? And I can come over here and now I can step through the code. See, step through is 1, keep stepping 2, 3, 4, 5, and so on. See? That's what stepping into does or step over. I'm basically watching each step of it.

Now, at any point now I can come down here. Let me Control A, delete. I can say, what is X right now? Question mark X. It'll tell me what X is. It's 9. And while I'm paused like this, while I'm stepping through this code, let's say I want to artificially inflate that value. I want to say, all right, I want to see what happens when X gets to 99. I don't want to wait for it though. So all you have to do, again, delete everything and say X equals, let's go to 95. Press enter. Now, I've set the value of X to 95. Now, watch it happens when I keep stepping. Look at 96, 97. So you can adjust the value of variables while your code is running with a breakpoint there. You just put a breakpoint on and then when it runs, you can stop it and set the value. You could do the same thing with form fields. Okay.

All right, let's stop that. Again, delete all this. You can run SQL statements down here. You want to do something? Let's say, you know, your customers. Okay, you got all your customers in here. And you want to add one to everybody's family size, but you don't want to take the time to go through and make a function or make a query and do all that. So if you know how to run SQL statements, you can do it right down here in the immediate window. All right, remember, my family size right now is 2. Okay, so I'm going to close this. Come right down here. And you can issue commands down here just like if you were in VBA, you can say do command. Run SQL or if you prefer current db.execute, whatever you want, update customer T set. Family size equals family size plus one. You can put a where condition whenever else you want to do. Hit enter. Nothing appears to happen, but now watch when I open up the customer table. Where's my family size? I was 2 before. Now, I'm 3. Look at that. You just ran an action query right in the immediate window. That's pretty cool. I do this all the time when I want to, you know, mess with values in here, but I don't want to have to go into the table and blah, blah, blah. This does not work with select statements, by the way, just like you can't run a do command SQL select statement. So you'd have to actually use an update, insert, delete, that kind of stuff.

You can use it to view form properties, report properties, any kind of properties, really. What is forms customer f.record source? Okay, it's customer T. What is the current database's name? See any property you can get in VBA, you can get down here in the immediate window. It's basically like you're executing code one line at a time. The question mark just means return that value. Think of it like message box, but it's just down here. Right? Control A, delete.

So, that's pretty much it. That's the immediate window or the immediate pane, however you want to talk about it in a nutshell.

If you want to learn more about error handling, debugging, the immediate window, breakpoints, all that stuff, Access Developer 15 covers all that stuff. We start out with some stuff, some moving objects between listboxes, lots of stuff covered in here, but in lesson two, this is what I call debugging level two. I covered really, really basic debugging earlier in the developer series, just to teach you the quick stuff, how to quickly check for errors and stuff. But in this video, we go through all the different stuff. On error, immediate window watches, breakpoints, all that stuff. And then we go into multi-select list boxes, which everyone asks me about too, that's really cool. We can select multiple items. So again, that's Access Developer 15. I'll put a link down below if you're interested.

But there you go, that's going to do it. That's your TechHelp video for today. I hope you learned something. Live long and prosper my friends. I'll see you next time.

TOPICS:
Immediate window in VBA  
Opening and displaying the immediate window  
Using debug.print for output  
Debugging and testing code snippets  
Executing VBA code in the immediate window  
Using the immediate window as a calculator  
Running functions and subroutines  
Manipulating object properties  
Using breakpoints to pause code execution  
Querying and setting variables during a breakpoint  
Running SQL commands in the immediate window  
Viewing and modifying form properties

COMMERCIAL:
In today's video, we'll explore the Microsoft Access Immediate Window and its powerful applications for debugging, testing, and issuing quick commands directly in the VBA editor. Whether it's utilizing debug.print to display loop outputs, running your custom functions, or executing SQL statements effortlessly, the Immediate Window is your go-to tool. You'll learn how to manipulate variables and form values on the fly and view form and report properties with ease. Perfect for developer-level users, this tutorial will guide you through practical examples to enhance your Access development skills. You'll find the complete video on my YouTube channel and on my website at the link shown. Live long and prosper my friends.

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

 
 
 

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: 6/17/2025 9:32:04 AM. PLT: 1s