An If…Then statement lets you determine whether or not to run a code segment. In this video, learn how to perform a task when conditions are met using an If…Then statement.
- [Teacher] So far in this course,…most of the example code has contained…subroutines or functions that run every time you call them.…There will be times though,…when you want part of your code to run.…Only when a particular condition is true.…You can use if, then statements,…to execute code conditionally.…I'll demonstrate how to do that in this movie.…I have opened the database sample file,…and I'll press alt f11 to move to the visual basic editor.…I want to work within a code module,…so I will click insert module,…and there we go.…
I'll define this subroutines, I'll type sub…and I'll just call it if, test,…followed by open and close parenthesis with…nothing in the middle,…'cause I'm not passing any data into the sub routine.…Now I can declare my variables so I'll do…Dim-c-u-r-Total,…which will represent the total of a sale,…as currency.…And a comma and the commission will also be a currency.…So c-u-r-C-o-m-m as currency.…
Then, enter.…We'll start by getting the total of the sale…through an input box, so that would be c-u-r-Total…
- Working with macros
- Running a VBA procedure
- Debugging VBA code
- Defining variables, constants, and calculations
- Displaying a calculated result in a message box
- Repeating tasks with loops
- Manipulating database objects
- Adding, editing, and deleting records
- Looking up values in a table
- Automating processes with macros
Skill Level Advanced
What you should know1m 38s
1. Introduction to Visual Basic for Applications
2. Define Variables, Constants, and Calculations
3. Add Logic to Your VBA Code
4. Debug Your VBA Code
5. Manipulate Database Objects Using DoCmd
6. Read and Manipulate Table Data
7. Manipulate a Database Using the Application Object
8. Control Forms and Reports Using the Me Object
9. Automate Processes Using Macros
Next steps1m 7s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.