Access VBA Macro Programming

(Joao Candeias) #1

The End..If statement shows where the conditional statements finish, or you can put the
entire If statement onto one line, which then would not require an End..If, as shown here:


If CurrentDb.Name= "C:\Temp\MyDB.accdb" Then MsgBox _

"Database path and name are correct"


However, note that a continuation character (space and underscore) has been used to get
all the code in, and you cannot use the continuation character between quotes (as part of a
string).
If you have multiple instructions to be executed, you can place the statements on a single
line as long as you separate each statement with a colon. However, this can become very
difficult to read and debug, and often several instructions must be carried out that preclude
putting everything on one line.


Chapter 4: Programming Basics: Decisions and Looping 37


Figure 4-1 Code for a conditional If statement

Free download pdf