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 > DoCmd.OpenForm < Round Up Cents 2 | Date Problems >
Back to DoCmd.OpenForm    Comments List
Pinned    Upload Images   @Reply   Bookmark    Link   Email  
Transcript
Richard Rost 
          
6 months ago
I use it in almost every one of my videos, but I haven't done a good TechHelp video on exactly what DoCmd.OpenForm is all about and what all of those parameters mean. There's lots you can do with it, and we've only scratched the surface of it. So in this video, we're going to run down a bunch of different uses for DoCmd.OpenForm.

Now, if you've watched any of my previous videos, you probably saw me use DoCmd.OpenForm. It's what you use to open another form. Here's the main menu form, and the main menu form just opens the customer list form, and from the customer list form, I can open up the customer form. That's DoCmd.OpenForm.

Now at its basic level, all it is is this: DoCmd.OpenForm and then a form name. But there's all kinds of stuff you can put after it. There's lots of different options in here. Some of them are completely useless, and some of them I use all the time, like the where condition.

In this video, we're going to talk about them. By the way, if you haven't done any VBA programming before and you want to learn, now's a great time. Go watch Intro to VBA. It's about 20 minutes long. It'll teach you everything you need to know to get started. In fact, a little bit of DoCmd.OpenForm. That's one of the examples we do in this video. So go watch this and come on back.

So here's DoCmd.OpenForm. And you can see I got a bunch of different commas in here because I want to get to this option, which is the where condition. We'll talk about this one first. The where condition is where you can specify criteria for the other form that you're opening. Now, if you want to just open the form and show all records, you don't need that. You literally just need that. But if you put that where condition in there, it'll now open up the customer form and show you the records where the customer ID equals the customer ID field on whatever form you happen to currently be on, which is customer list. You can see that right up there. So on the customer list, which is this form, let me close this and open it back up again. Here's the customer ID field. So if I'm sitting on this one and I double-click here or hit the open button, it runs that code and it opens a customer where it's customer number nine. But you can also put any other kind of a where condition in here that you want. You can say something like state. The state field state equals and then you could just put it right inside the quotes if you want to. You could put New York in there. Now remember quotes inside a quote, you need double, double quotes. So if you want to put a string value in there, it looks like that.

So if I save it now and if I run it and I open the customer, I get all the states where it equals New York. See? And there's three of them. And if you want to grab that field off of this form like this, you need another quote like this. Like that. See? And now it gets the state field off of this form, and that becomes a double quote, and that becomes a double quote. These double, double quotes get very, very confusing. But I bring them up again here because a lot of people get stuck on them and b, you're going to run into this a lot if you do any kind of criteria here with strings. Strings always need those double, double quotes. I got a whole separate video that goes into a lot more about double quotes, double, double quotes, and all kinds of stuff. So check this video out if you want to learn more about this topic.

Let's put this back to something simple. Customer ID equals customer ID. Now let's take a look at some of these other options that are in here. Let's go back to the first one. View as AC form view equals normal. This is how you're going to view the form when it opens. Now, if you want to see the different options, backspace and hit comma, and it will show you that list there with the IntelliSense. The default is normal. Now two of these you'll never use because they're not in access anymore. There's pivot chart and pivot table. These used to be available in older versions of access. Microsoft got rid of it around 2013 or so. These are just in here for backward compatibility. Ignore them if you want to do a pivot table or a pivot chart, use Excel.

Design view is okay for you as a developer. If you want to make a database with a button in it that opens a form in design view so that you can then quickly go in there and play with it. I have this in my database. I got a couple of spots where I'm always making tweaks to a form. So I just put a button there to open it up in design view. You can certainly do that. Your end users, though, should never be poking around in design view, so you don't want to make that for them. DS is a datasheet view. Again, I almost never use datasheet views for forms, but that's basically the table view. Layout view if you want to use that. Again not one of my favorites. Normal is normal. It's what we usually use. And then there's preview. We just kind of like a print preview version, but we don't print forms. We print reports. So I'm never going to use that one either. So out of this list, I'd say AC normal, which is the default view, is 99.9% of the time that's what you're going to work with.

And since it is the default, we can get rid of that. We don't need that. What's next up here? Let's actually make this easier. Let's just get rid of that stuff there. So we are comma. We don't need that. Comma is the filter name next. Now the filter name is not what you think. You can actually create saved filters with forms, but you know what? I never use them. I haven't used one in 30 years. So I don't bother with them. I'm not going to use it. Just ignore filter name.

Where condition is the next thing we just talked about. That's the first thing we talked about. That's how you can control what data is displayed when you open up the form. Data mode is the next one. Now this is actually pretty handy. AC form property settings is the default value. Now what that means is it's going to look at the property settings in the form itself as to whether or not you can add records, edit records, delete records, and so on. There are properties for all of those things. So if you just use that, it's going to use the form properties only. But you can override those settings with this command. So AC form add will put you into data entry mode only. It's the same as the data entry mode property in the form. So if you put AC form add in here and then try to open a customer, it doesn't matter. It's going to go to a blank new record, and you're in add a record mode. Same thing with the other ones. AC form edit means no matter what the forms property settings are, even if allow edits is off and the property settings, if you do that, it will allow you to edit the record. Read only is exactly what it says. If you want to open it up and only show data, you don't want to use it to be able to edit stuff. This is a good setting if you've got a form where normally, like the managers, can get in there and edit stuff, but the regular users can't. You can make them a separate button. And now with read only, if they come in here and try to do something, they can't type in right now and edit it. So those settings are definitely helpful. The default is AC form property settings. We're going to leave that alone.

Next is window mode, and it's off my screen here. Let me slide over to get more. Let's see if I can get it all on the screen. There we go. It's window mode. AC window mode is AC window normal. There's your options here. Normal. We've got dialogue hidden and AC icon. Now icon used to be, in the old days, it would be an icon on the bottom of the screen, but now it just opens the window minimized. That's all that thought. So if you pick AC icon, if you open it now, it opens up down here minimized. And you can use other VB code if you want to restore it or to close it. I almost never use that one. I'd say probably don't bother with that one. What else have we got? Then there is hidden, which opens up the window hidden. Now this is actually sometimes helpful. I sometimes open hidden timer windows with a timer event running in it. The user can't see it, but it's still open, and it's still doing stuff. You've got a background process running, that kind of stuff. And of course, you can use other VB code to make that visible. You can say the form's form name, visible.equals true, and it will make it visible.

Dialog is a dialogue form. What a dialogue form is it opens up modal and pop up. And it stops execution of your code until the user closes that form. If you don't know what modal and pop up is, go watch this video. Modal basically means that it's in front and you can't go behind it. You can't do anything to any of the forms behind that window until you close the one on top. And pop up just means it stays on top of other windows all the time. You can be modal and not pop up. You can be pop up and not modal, or you can be both modal and pop up or not or neither modal nor pop up. It can be any of those four combinations. So if I pick AC dialogue here and I open up a form. Now I open it up on my other screen. That's one thing with pop up windows is they open up anywhere. Wherever they might have been last saved and if you have a multi-monitor setup, they're not reliable. I don't like using pop up forms myself. But since this is modal, you can see I can't click behind it.

So that's all of those, I think. We've got AC hidden window, normal, icon, dialogue. Let me get rid of that. We'll go back to normal. And the last option, which I don't think you can see. Okay. You can see I use it. It's way over there. Open args. What is open args? Open args is you can send a parameter into the form when it opens. Like you can send a parameter in here like, "my color equals blue" or something like that. You can send any kind of information you want into the form, and it's treated as a parameter, as an open argument.

And if you want to learn more about open args and the modal pop up stuff, go watch my custom message box video. I teach you how to use open args in here. We open up a form, which is our custom message box. And we can send into it an open args that says, "hey, make your color this", "make the prompt that", "make the caption this", "these are the number of buttons you need", and so on. Those are open arguments.

One more thing I like to mention to people when we're talking about this is that you don't need all of these commas in here. If all you want is the where condition, I always make a joke in my video, so my students will remember it. I say, "okay, do command open form for me" and then I go, "comma, comma, comma". Because I do stupid things in my lesson. So you remember there's three commas there before the where condition. But if you don't want to do that, you can literally just come in here and say, "whereCondition: = customerID = customerID" like that. That colon equals allows you to put that anywhere on that line that you want to. If you see other code where people do this, this is the exact name of the parameter right here, and then you're just specifying the value. That way, you don't have to have all these commas in here and get the right spot. You just make sure you have the right name.

So there you go. That's 99.9% of everything that I've ever used DoCmd.OpenForm for. All those other little parameters that I said, don't worry about them. Don't worry about them. I don't really use them. And I've been doing this a long, long time. If you want to learn more, if you like learning with me, if you like my videos and how I teach, well, I got tons of developer lessons where not only do we cover DoCmd.OpenForm, but we cover a lot of the other DoCmd stuff. There's lots of commands in the DoCmd stuff. And I cover most of them over in my developer course. So check it out. So on my website, I am thinking about the 48 now, 48 levels. Lots of stuff for you to learn. But that's going to do it for today, folks. That's your TechHelp video. Hope you learned something. Live long and prosper, my friends. I'll see you next time.

TOPICS:
Using DoCmd.OpenForm in Microsoft Access  
Specifying form name in DoCmd.OpenForm  
Using the Where Condition parameter  
Double quotes in string criteria  
Form view options: Normal, Design, Datasheet, Layout  
Backward compatibility options: Pivot chart and table  
Filter name option explanation  
Data mode options: Add, Edit, Read only  
Using window mode options: Normal, Dialog, Hidden  
Understanding modal and pop up forms  
Using OpenArgs to pass parameters  
Referencing parameters by name in DoCmd.OpenForm

COMMERCIAL:
In today's video, we're going to explore the DoCmd.OpenForm in Access VBA. You'll learn how to open forms and utilize powerful options like the where condition to filter data. We'll discuss various view modes, from the underutilized design view to the commonly used normal view. You'll see how to control data modes for editing or read-only access and dive into window modes like hidden and dialog. Plus, we'll show how to pass parameters with open args for more dynamic form interactions. If you're ready to enhance your database skills, this video is for you. 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 DoCmd.OpenForm.
 

 
 
 

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: 7/14/2025 6:19:37 PM. PLT: 2s