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 > Intro to VBA > < Relational Combo | Hyperlinks >
Intro to VBA
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   5 years ago

Introduction to Visual Basic for Applications


 S  M  L  XL  FS  |  Slo  Reg  Fast  2x  |  Bookmark Join Now

In this video, I'm going to teach you how to start programming in Microsoft Access VBA. If you've never done any programming before, don't worry. I'll show you how to get started and walk you through it step by step. We will learn how to work with the VBA Editor, create a MsgBox, learn how to open a form with DoCmd.OpenForm, and set a value in a form field. 

Patricia from Ann Arbor, Michigan (a Platinum Member) asks: I've seen in several of your TechHelp videos where you mention "you can do this with a couple lines of code." I've been using Access for a few years, but I've never done any VBA programming before. Can you tell me where do I put this code, and how do I get started?

Free Template

Members

Members will learn how to create a button to open a form to a specific record. We'll put a customer list box on the main menu. Pick a customer, click the button, and that customer's record will open. Then we'll learn about Event programming. We'll use the On Double Click event to do the same thing by just double-clicking on that customer list box. Then we'll learn about the If / Then / Else statement. If the user doesn't pick a customer from the list and then click the open button, then they will get an error message. Lots more too!

Silver Members and up get access to view Extended Cut videos, when available. Gold Members can download the files from class plus get access to the Code Vault. If you're not a member, Join Today!

Links

Learn More

FREE Access Beginner Level 1
FREE Access Quick Start in 30 Minutes
Access Level 2 for just $1

Free Templates

TechHelp Free Templates
Blank Template
Contact Management
Order Entry & Invoicing
More Access Templates

Resources

Diamond Sponsors - Information on our Sponsors
Mailing List - Get emails when new videos released
Consulting - Need help with your database
Tip Jar - Your tips are graciously accepted
Merch Store - Get your swag here!

Questions?

Please feel free to post your questions or comments below or post them in the Forums.

Keywords

microsoft access, ms access, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #instruction, #learn, #lesson, #training, #database, VBA, Choose Builder, Code Builder, Project Pane, Properties Pane, Immediate Pane, MsgBox, parameters, optional parameters, DoCmd.OpenForm, Set Value, Turn Off Choose Builder Box, Options, Object Designers, Always Use Event Procedures, Open Form to Specific Record, On Double Click Event, On Dbl Click, DblClick, If Then Else, Microsoft Access VBA, Access VBA Tutorial, Access VBA for Dummies

 

Comments for Intro to VBA
 
Age Subject From
2 yearsIntro to VBA Extended CutPaul Page
3 yearsnothing happensVannak Hou
3 yearsMacros vs VBAMichael Olgren
4 yearsIntro to VBALauna Sallai

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to Intro to VBA
Get notifications when this page is updated
 
Intro In this video, I will show you how to get started with programming in Microsoft Access VBA (Visual Basic for Applications) even if you have no prior experience. We will cover how to use the VBA Editor, create a simple message box, open a form using VBA with the DoCmd.OpenForm command, and set a value in a form field with code. I'll also demonstrate best practices for naming buttons and show you how to simplify your workflow in the VBA environment by adjusting your options.
Transcript Welcome to another TechHelp video brought to you by AccessLearningZone.com. I am your instructor, Richard Rost. In today's video, I'm going to teach you how to start programming in Microsoft Access VBA - that's Visual Basic for Applications. If you've never done any programming before, don't worry. I'll show you how to get started and walk you through it step by step. VBA is easy once you learn how.

You will learn how to work with the VBA Editor, create a message box, learn how to open a form with the DoCmd.OpenForm command, and set a value in a form field.

Today's question comes from Patricia in Ann Arbor, Michigan, one of my platinum members. Patricia says, I've seen in several of your TechHelp videos where you mentioned you can do this with a couple lines of code. I've been using Access for a few years, but I've never done any VBA programming before. Can you tell me where do I put this code and how do I get started?

Yes, of course, Patricia. I'd be happy to give you and everyone else who's never done any VBA programming before the quick basics of how to get started.

Now before we get started, I want you to go watch my blank database template video. In that video, I show you how I like to set up my initial Access database with all my preferences and settings. I'll also show you how to set up a basic customer table and customer form and a main menu. So go watch that first and come on back. I'll put a link down in the link section below.

Now if you want to go to my website and download my Intro to VBA template, you'll find a link down below in the link section. It's right there. It's a special copy of the blank database that I put together just for this lesson. It's got just what you need for today's class.

If you don't want to download it or you can't download it, that's not a problem. You can work with a blank database. That's fine. But if you can, go download this template from my website. It's a free template.

OK, so here I am inside the Intro to VBA template. It's real simple. It's got a main menu, a customer table, and a customer form. I used the command button wizard to create this button right here that just opens up the customer form. If you watched my blank template video, then you know how I created that.

Most of the time, when you use VBA code inside of Access, your code is usually going to run in a button or some other kind of event. Buttons by far are the most popular. You click a button and something happens.

Now when you use the command button wizard, the wizard usually creates a macro for you. Let's take a look at it. Right click on the form, go to Design View. Now right click on the button and go to Build Event. This opens up the embedded macro that's in that button.

OK, it says OpenForm. CustomerF is the form name, view in Form View, window view is normal. That's all fine and dandy. There's nothing wrong with macros. Macros are OK, but macros are very limited. VBA is much, much more powerful, and you can actually do this with just one line of code, which I'm going to show you in a few minutes.

The problem with VBA is everyone gets intimidated when they hear about programming and coding and all this stuff. Don't worry about it. It's super simple to learn how to program in Access VBA.

All right, so let's close this macro. I'm going to shut down this action catalog. Close that.

All right, let's create our own button in here to do the same thing. But this time, we're going to do it in VBA code. I think even the name "coding" sometimes makes it sound like it's secretive. It's not. It's super easy. I'm going to show you how.

OK, so we're going to start this button just like we start any other command button. Go to Form Design, find the button right there. They used to be called command buttons; now they are just buttons. Drop it on your form.

Now, the command button wizard starts out, but we don't want to use the wizard. We're going to write our own code for this button. So hit Cancel. Cancel that wizard.

OK, I'm going to resize it so it's about the same size as that guy. Let's see. About the same height, about the same width.

OK, let's change the caption. So let's call this "My Button." OK, and it's a little bit shorter now. There we go. My Button.

Now in addition to changing the caption, what's on the button's face, I like to change the name of the button to give it a good name. So double click on that button; that will bring up the property sheet. Go to the "All" tab. The name of it right now is Command12 or some other number. That's not a very good name, and we're going to see that name in our coding in our VBA window. So we're going to change that to MyFirstBTN. I like to end my button names in BTN. This is my first button.

I'm going to resize that a little bit. That's a little big.

Now, how do we get to the code? How do we get to the coding behind that button? There are a couple ways to do it. The easiest way: right click on the button and go to Build Event, just like we did with the other one.

Now, you'll get this Choose Builder window. There's Macro Builder. We don't want to build a macro. We don't need the Expression Builder. That's something totally different. Code Builder is what we're going to pick to get into the VBA Editor. So pick Code Builder and then hit OK.

Now, this window pops up. It's the Microsoft Visual Basic for Applications window. This is where your coding happens. So we write all your programming.

Now there's a bunch of stuff on here that we don't need that I find makes things confusing for beginner users. At the bottom here, this section that says Immediate. If you see that, close that. Just like these other two panes over here, we don't need this Project pane or the Properties pane. Turn all that stuff off.

Now look at it. See how easy it is? It looks nice and simple now. Don't worry about all these crazy buttons across the top. In fact, you might have a different set of buttons than I do. Don't worry about all that. We don't need any of that right now.

Now don't worry about a copyright notice. I put that across the top of all my databases. That won't be in your databases that you create. Don't worry about these next two lines. Access puts them in every database. Ignore them for now. You don't need to worry about what they are.

This is all we care about right here. It says Private Sub. MyFirstBTN_Click and then End Sub. Sub stands for subroutine. Everything that happens between the Sub and the End Sub will run when you click that button. That's how Access knows what to do when you click on MyFirstBTN. Hence it's MyFirstBTN_Click.

So come in here. Put your cursor right between those two lines. Hit Enter a couple of times. Put some blank lines in there.

Now the traditional first program that every new programmer writes is something to make the computer say "Hello, world." I've been doing that since I was eight years old, programming on my Tandy Radio Shack TRS-80 computer back in like second grade.

So we're going to hit Tab because it's always good form to tab in. Then we're going to use the message box command: MSGBOX. That is a command that pops a message up on the screen. Hit space. Now you'll see this little guy pop up just to help you know what the parameters are for message box. Parameters are bits of information that you send to message box to tell it what to do.

The first thing and the only thing that you need to worry about right now is the prompt. What do you want message box to say? I want it to say, inside quotes, "Hello, world!" Close quotes. All the rest of those parameters you see there inside square brackets - that means they're optional. You don't need to worry about them.

Then press Enter. That's it. You're done. You just wrote your first program in VBA.

We're going to save this (Ctrl+S), or you can click on the little floppy icon if you want to. Come back over to your Access window. Now I'm going to close the form, reopen it again, main menu, and here's my button. Ready? Click. And boom. There you go. Hello, world. Congratulations. Give yourself a round of applause.

That's a message box. Message boxes are handy. I use them all the time for displaying messages for the user. For example, "Error: You typed in a credit limit that's too high." That kind of stuff. You use message boxes constantly. So that's the most popular thing that most people want to learn how to do.

OK. So now that we know how to create our own command button, let's make another one. Let's mimic this guy. This guy uses a macro though. Let's do the same thing: open up the customer form, but we're going to use VBA code.

So let's right click, go to Design View. I'm going to slide this one up just a bit. Let's create another button. Drop it down here. Cancel the wizard. Make it about the same size as the other ones. Like that. If you're not sure if it's high enough, just bring it next to the other. That's close enough.

OK, let's change the caption to "Customers 2." Customers 1, that's "Customers 2." Let's give it a name. Let's make this OpenCustomerBTN like that. I think the other one is just CustomerBTN. I named that one in the other video. This one will be OpenCustomerBTN.

OK. Right click, Build Event, Code Builder, hit OK.

Now we're inside Private Sub OpenCustomerBTN_Click. That's why naming that button is important. Otherwise, it will be Private Sub Command14_Click, and you won't have any idea what button it is.

Now don't worry about the word Private. Private just means only this form can use this subroutine. You can make the stuff public as well, which means other forms can use it, but Private is the default. Don't worry about that right now. We'll talk about that in a much later class.

OK. Now what do I want to do in here? Put a couple of blank lines in there. Tab in. I want to open up another form.

The command for that is DoCmd. DoCmd.OpenForm. So you get a list there; IntelliSense, that's called, to tell you what all the different commands are. There's OpenQuery, OpenFunction, OpenReport, all kinds of different stuff. Space, there's your parameters. The only one you need is the form name. Inside the quotes: "CustomerF." That's it.

I like to get rid of these blank spaces in here. Ctrl+Y will get rid of those blank spaces. It just keeps your code looking nice and clean and compact.

As far as these commands go, you just have to learn what they are. It's like anything else. It's like Excel: you have to learn the functions. In Access, you have to learn how to use the different commands and stuff. It's that simple. You just have to remember what they are. Make a cheat sheet at first if you want to. Message box, open form, there's a couple other popular ones you'll use from time to time.

But that's it. That's all you need. One line of code to open a form. Save it (Ctrl+S). Come back over here. I'm going to close my form, open it back up again, and ready, click. That's the same thing.

Now, this is a situation where it doesn't really matter if you use a macro or VBA code, but as you can see, the VBA code is one line. It's really easy to do. In the long run, as you learn VBA, you'll find it's much, much more powerful than programming with macros.

Now, we're going to make one more button. The next most popular thing that people always want to see is how do you click a button to change some value on the form? For example, let's say Family Size here. I want to put a button right next to it so that I can click on that button, and every time I click on it, it increments the family size by one. So I click on the button, it goes to three. Click on the button again, it goes to four.

Simple example, but this is how I teach you how to program - really nice, simple, easy examples. Then we slowly get more complicated as we go along.

So let's make a button right here. Let's go to Design View. But before we make that button, first, a word from our sponsors - and that's me. I have to sneak in a little advertisement once in a while.

If you want to learn a lot more about programming in Visual Basic, take my Access Developer Level 1 class. It's over an hour long, I cover all the basics, and I go in a lot more detail, too. I've just glanced over the surface of it right now. We'll talk about all these things: statement, procedures, parameters, multiple command arguments, SetWarnings, If-Then-Else statements, all kinds of different stuff. This is just in level one.

As of right now, I've got about 30 some levels of developer, so you can go as deep as you want. We'll learn how to open queries, we'll learn how to set values, and we'll make this little button here so you can type in the billing address, click "Same as Billing," and it'll fill in the shipping address automatically for you. All kinds of cool stuff, just in level one. After that, I've got lots and lots of lessons available.

So if you really want to learn how to become an Access developer and learn how to program, you're in the right place. Check out my website.

OK, advertisement's over. Let's go back to work.

Let's make this form a little bit bigger. Let's put a button right down here next to Family Size. I'm going to grab the button, drop it right there, and cancel the wizard. I'll put in the caption maybe "+1" like that. You can do +1/-1 if you want to. That would be good homework for you - do the same thing, but for -1. So there's a +1 in the button.

What are we going to name this button? Let's call this AddFamilySizeBTN. OK, right click, come up to Build Events, way up there. Code Builder - this Choose Builder window is a little annoying. I'll show you how to turn it off in just a minute. Code Builder, hit OK.

There's my VBA window. Now, where's my other code? The other stuff that I just wrote? Well, don't panic. We're on the customer form now. The other code is in the main menu form, so you didn't lose anything. It's still in there.

Now, what do we want to do? I want to add one to the value that's in the Family Size field. Let's make sure of the name of the field here: Family Size right there. That's the name of the field in the control source, but the name is what we're interested in. This box right here, this text box, is named FamilySize.

Go back to your Editor window. I always leave the code editor open, by the way. I just minimize it or hide it.

Come right in here, Enter, Tab in, type in: FamilySize = FamilySize + 1. Then press Enter. That's it. That's all you have to do. Take whatever the value of FamilySize is right now, add one to it, and then put that in FamilySize. If it's currently 2, it's going to get set equal to 3, then 4, then 5. Every time you click on that button.

Save it (Ctrl+S). Come back over here. I'm going to close this, open it back up again, and then click my button. Boom. There's a 3. Click it again. Boom, 4, 5, 6, 7, 8, 9, 10. That's a pretty big family!

That's it. That's how easy this is. It's not hard. Programming in VBA is super simple.

Now, the one thing I want to show you is that code editor thing - the Choose Builder window. That's kind of annoying. Every time you go and want to create, because I always use VBA now. Once I learned VBA, I almost never make macros. Like, 99.99% of the time. So that little window is just one more step that I don't need.

How do you change it? Go to File, come down to Options, go to Object Designers, scroll down a little bit underneath the Form/Report Design View section, and check this box that says "Always Use Event Procedures." Now you won't be bothered for that Macro Builder/Expression Builder thing.

Hit OK. It says you have to close and reopen the database, but chances are you don't.

Now if I go to create another button, right click Design View, grab a button, drop it down here, cancel the wizard. If I right click and go to Build Event, the VBA window pops right up and I didn't get bothered to choose a builder. Now I'm in Command15_Click. See? That's why you want to make sure your buttons have a good name. I'm going to delete that Private Sub because I don't need it. Then I'm going to close this window, and I'm going to delete that button that I really don't want. I'm going to shut this down, open up the main menu, and I'm all good.

Now I know how to message box, I know how to open up a form, and I know how to set a value in a form field using VBA. See, you learned all that in less than 20 minutes. I told you, this stuff is easy. It's not that hard.

If you want to learn more, "Intro to VBA," I put together an extended cut for the members. It's 15 minutes long, and it goes over more beginner-level programming stuff. For example, we'll put a list box on the main menu with our customers in it. I'll show you how to then make a button to open whatever customer the user picks. Here's my list box. Pick OpenCustomer, and there's that customer. Pick a different one, OpenCustomer, there they are.

Then I will teach you event programming, how to do things when a certain event happens. For example, the On Double Click event. What happens if instead of clicking that button, I want to double-click on the customer list? Instead of clicking that button, it's easier to just double-click on James Kirk. There it is. That's a double-click event.

Then finally, we'll learn about the If-Then-Else statement. For example, if the user doesn't pick a customer, and that list is null, we want to intercept that and give a proper message with a message box: "Pick a customer first." That's all covered in the extended cut for members, 15 minutes long. Silver members and up get access to all of my extended cut videos, and gold members can download these databases.

How do you become a member? Click the Join button below the video. After you click the Join button, you'll see a list of all the different types of membership levels that are available.

Silver members and up will get access to all of the extended cut TechHelp videos, live video and chat sessions, and more.

Gold members get access to a download folder containing all the sample databases that I build in my TechHelp videos, plus my code vault where I keep tons of different functions that I use.

Platinum members get all the previous perks, plus access to my full beginner courses and some of my expert courses. These are the full-length courses found on my website and not just for Access. I also teach Word, Excel, Visual Basic, ASP, and lots more.

But don't worry, these free TechHelp videos are going to keep coming. As long as you keep watching them, I'll keep making more.

If you liked this video, please give me a thumbs up and feel free to post any comments that you have. I do read them all.

Make sure you subscribe to my channel, which is completely free, and click the bell icon and select All to receive notifications when new videos are posted.

Click on the Show More link below the video to find additional resources and links. You'll see a list of other videos, additional information related to the current topic, free lessons, and lots more.

YouTube no longer sends out email notifications when new videos are posted. So if you'd like to get an email every time I post a new video, click on the link to join my mailing list.

If you have not yet tried my free Access Level 1 course, check it out now. It covers all the basics of building databases with Access. It's over three hours long. You can find it on my website or on my YouTube channel. If you like Level 1, Level 2 is just $1, and it's also free for all members of my YouTube channel at any level.

Want to have your question answered in a video just like this one? Visit my TechHelp page and you can send me your question there.

Click here to watch my free Access Beginner Level 1 course, more of my TechHelp videos, or to subscribe to my channel.

Thanks for watching this video from AccessLearningZone.com.
Quiz Q1. What is the purpose of using VBA (Visual Basic for Applications) in Microsoft Access?
A. To add advanced, programmable functionality to your Access applications
B. To create macros for simple tasks
C. To design forms and reports
D. To store raw data

Q2. What is the VBA Editor used for in Access?
A. Writing and managing VBA code for database objects and events
B. Editing table data directly
C. Creating queries using SQL syntax only
D. Designing forms visually

Q3. When you create a button by default using the Command Button Wizard, what is typically created?
A. An embedded macro
B. VBA code behind the button
C. A data macro
D. An SQL statement

Q4. Which builder should you select to enter the VBA Editor when attaching code to a button?
A. Code Builder
B. Macro Builder
C. Expression Builder
D. Property Builder

Q5. What is the traditional first program most new programmers write, as shown in the video?
A. Displaying "Hello, world" in a message box
B. Opening a report in Print Preview
C. Calculating the sum of two numbers
D. Creating a new database table

Q6. Which VBA command is used to display a message to the user in a pop-up window?
A. MSGBOX
B. ShowMessage
C. AlertUser
D. PopUpMsg

Q7. What is the VBA command to open a form called CustomerF?
A. DoCmd.OpenForm "CustomerF"
B. MsgBox "CustomerF"
C. Open.CustomerF()
D. RunForm("CustomerF")

Q8. What is the advantage of renaming your button from names like Command12 to something like MyFirstBTN?
A. To make it easier to identify and reference in your code
B. To increase processing speed
C. To lock the button from changes
D. To hide the button from users

Q9. How can you automatically open the VBA Editor when assigning an event to a control, bypassing the Choose Builder window?
A. Check "Always Use Event Procedures" in Object Designers options
B. Uninstall Macro Builder
C. Set the default form view to VBA
D. Lock the button's properties

Q10. How do you increment a numeric value in a form control named FamilySize by one using VBA?
A. FamilySize = FamilySize + 1
B. FamilySize = FamilySize + "1"
C. FamilySize = 1 + 1
D. FamilySize = (FamilySize)++

Q11. What are message boxes commonly used for in Access VBA?
A. Informing users of errors or important information
B. Formatting form layouts
C. Storing user preferences
D. Importing data

Q12. What is the primary difference between macros and VBA in Microsoft Access?
A. VBA offers more power and flexibility compared to macros
B. Macros have more security features than VBA
C. Macros support more SQL operations than VBA
D. VBA can only be used with tables

Q13. What is the purpose of the "Private Sub MyFirstBTN_Click...End Sub" code structure?
A. It defines a subroutine that runs when the button is clicked
B. It starts a new database session
C. It creates a query automatically
D. It is used to close a form

Q14. What should you always do before writing code for a new button according to the video?
A. Rename the button with a meaningful name
B. Delete all existing code
C. Create a new table
D. Add the button to the navigation pane

Q15. Why might you create a cheat sheet when learning VBA commands?
A. To quickly recall common commands and their syntax
B. To skip learning VBA entirely
C. To share your database with others
D. To standardize form names

Q16. What is recommended to do after writing or modifying VBA code in the editor?
A. Save your changes before testing
B. Compile the database manually
C. Restart Microsoft Access
D. Backup your table structure

Q17. Which of the following tasks can you accomplish using VBA, based on the examples in the video?
A. Display messages, open forms, and update form controls
B. Only design forms
C. Only create tables
D. Only sort query results

Answers: 1-A; 2-A; 3-A; 4-A; 5-A; 6-A; 7-A; 8-A; 9-A; 10-A; 11-A; 12-A; 13-A; 14-A; 15-A; 16-A; 17-A

DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks.
Summary Today's video from Access Learning Zone is all about getting started with programming in Microsoft Access VBA, which stands for Visual Basic for Applications. My goal is to help those of you who have never written any code before and might feel overwhelmed at the idea of programming. I'll walk you through the basics, step by step, to show you just how straightforward it can be.

We will start by looking at the VBA Editor and learn how to create a message box, open a form using the DoCmd.OpenForm command, and update values in a form field.

For context, the topic for today comes from a question submitted by a viewer who has been using Access but has never tried programming with VBA. She wanted to know where to write code and how to get started. This video is perfect for anyone in that situation.

Before diving into coding, I recommend starting with my blank database template. That video explains how I usually set up a new Access database, including setting up a basic customer table, a customer form, and a main menu. It's a good foundation for what we're doing here, so if you need a starting point, check out that lesson and come back when you're ready.

I've also created a special Intro to VBA template for this lesson, available for free download on my website. It's a simplified version of the blank database, containing just what we need today, but you can work with any blank database if downloading is not an option.

Inside the Intro to VBA template, you'll find a main menu, a customer table, and a customer form. There is a button on the main menu that opens the customer form. I used the command button wizard to set up that button, which means it runs a macro by default. However, macros in Access have limitations, and with VBA you can do much more, often with far fewer lines of code.

When you use the command button wizard, Access typically creates a macro. You can inspect this by switching the form into Design View and looking at the button's event. The macro just tells Access to open a certain form in a particular way. While macros are serviceable, VBA offers much more flexibility and power for automating tasks and responding to user actions.

To get started with VBA, you can create your own button the same way you create any command button in Design View. Instead of letting the wizard create a macro for you, you'll cancel the wizard and set things up yourself. It's best practice to give your controls clear, descriptive names. For example, name your button something meaningful like MyFirstBTN instead of the default Command12.

To write code for your button, right-click on it and choose to build an event. Select the Code Builder option to open the VBA Editor. This is where you'll write your code. The Editor window can appear cluttered at first, but you can close any extra panes to keep things clean and easy to focus on.

In the Editor, you'll see a Private Sub for your button's Click event. Anything you write between the Sub and End Sub lines will execute whenever the button is clicked. For your very first program, you can display a message box. Just type the command to show "Hello, world!" in a message box. That's all that's needed for Access to pop up a friendly greeting when the button is pressed. Simple and effective, this basic exercise is a classic way to start learning any programming language.

Message boxes are useful for displaying information to users, like reminders or error messages. They're one of the most common tasks you'll perform with VBA.

Next, let's look at how to use VBA to open another form. Instead of using a macro, you can place a single line of VBA code in your button's Click event to open the CustomerF form. By naming the button something like OpenCustomerBTN, it's easy to keep track of what your code is doing. The command in VBA is concise and easy to read. Over time, as you learn more about VBA, you'll find that it's vastly more powerful and flexible than relying on macros.

Many people also want to use buttons for updating information on forms. For example, maybe you want to increment a "Family Size" field whenever a button is clicked. You can set up a button next to the Family Size field, give it an appropriate name like AddFamilySizeBTN, and write a simple line of VBA code to add one to the current value every time the button is clicked.

In every case, it's helpful to use clear, descriptive names for your buttons, as these names show up in your code, making it much easier to understand and maintain what you've built.

One point of convenience in Access is changing the default behavior so that the Code Builder opens directly when building events for controls, instead of having to choose between macro, expression, or code builders each time. You can change this setting by going to File, then Options, then Object Designers, and checking "Always Use Event Procedures." This saves you time if you do most of your automation with VBA.

By now, you've learned how to display a message box, open a form, and change a value on your form, all with simple VBA code. As you can see, getting started with Access programming is much easier than it might seem at first glance.

For those who want to go further, I offer a full Access Developer Level 1 class that goes into much more detail, covering statements, procedures, parameters, multiple command arguments, conditional statements, and much more. There are many additional levels available if you really want to master Access development.

For members, I've put together an extended cut of this lesson. In the extended cut, I show how to add a list box of customers to the main menu and create a button to open whichever customer the user selects. I also explain event programming, such as the On Double Click event, so you can perform actions when users double-click on items. Finally, I cover the If-Then-Else statement, so if the user tries to open a customer without making a selection, your program can deliver a helpful warning. The extended cut is fifteen minutes long and covers more beginner-level programming concepts. Silver members and up can access all my extended cut lessons, and gold members can download the databases used in these videos.

Silver membership gets you access to all extended cut videos, live sessions, and more, while gold membership adds the ability to download all of my sample databases and gives you access to my code vault. Platinum members get all those perks plus entrance to my full-length beginner and some expert courses, which cover not just Access, but Excel, Word, Visual Basic, ASP, and more.

These free TechHelp videos will keep coming, so you can continue learning as long as you follow along. If you found this lesson helpful, I'd appreciate a thumbs up. Please leave any comments or questions you have, as I do read them all.

Make sure to subscribe to my channel, which is completely free, and click the bell icon to be notified about new videos. For more resources and detailed information related to today's topic, visit my website using the link provided. There you'll also find other lessons, free courses, and additional learning materials.

If you want email notifications about new lessons, since YouTube no longer sends out emails, you can join my mailing list via the link on my site.

If you've not tried my free Access Level 1 course, be sure to do that. It covers all the basics and is over three hours long. Level 2 is just one dollar, or free for all YouTube channel members.

And if you want your question answered in a future video, visit the TechHelp page on my site to send it in.

You can find a complete video tutorial with step-by-step instructions on everything discussed here on my website at the link below.

Live long and prosper, my friends.
Topic List Working with the VBA Editor in Access

Creating a message box with VBA

Opening a form using DoCmd.OpenForm

Setting a value in a form field with VBA

Creating and naming buttons for VBA events

Adding VBA code to button click events

Switching from macros to VBA in Access

Customizing the VBA Editor layout for beginners

Renaming form controls for better code clarity

Using MsgBox for user notifications

Using DoCmd.OpenForm to open forms

Incrementing a numeric field value with VBA

Configuring Access to default to Event Procedures

Saving and testing VBA code in Access forms
 
 
 

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: 2/12/2026 10:35:42 PM. PLT: 1s
Keywords: TechHelp Access VBA, Choose Builder, Code Builder, Project Pane, Properties Pane, Immediate Pane, MsgBox, parameters, optional parameters, DoCmd.OpenForm, Set Value, Turn Off Choose Builder Box, Options, Object Designers, Always Use Event Procedures, Open  PermaLink  Introduction to VBA in Microsoft Access