From the course: Access: VBA
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Perform a task when conditions are met using an If…Then statement
From the course: Access: VBA
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Repeat a task using a For…Next loop5m 5s
-
(Locked)
Step through all items of a collection using a For…Each loop4m 59s
-
(Locked)
Repeat a task using a Do…While loop5m 32s
-
(Locked)
Perform a task when conditions are met using an If…Then statement6m 20s
-
Select actions using a Case statement6m 17s
-
(Locked)
-
-
-
-
-
-
-