Databases Reference
In-Depth Information
Case Else
' statements to execute otherwise
End Select
Note that the Case Else part is optional. To illustrate, the following code is the Select
Case version of Example 12-1 in Chapter 12 (see the discussion of the Section 12.4.3)
that displays the type of a file based on its extension. I think you will agree that this is a
bit more readable than the previous version:
Sub ShowFileType(FileExt As String)
Dim FileType As Variant
Select Case FileExt
Case "mdb"
FileType = "Database"
Case "txt"
FileType = "text"
Case "dbf"
FileType = "dBase"
Case Else
FileType = "unknown"
End Select
' Display result
MsgBox FileType
End Sub
Note that VBA allows us to place more than one condition in the same Case statement
(separated by commas). This is useful when more than one case produces the same result.
13.7 A Final Note on VBA
There is a lot more to the VBA language than we have covered here. In fact, the
Microsoft VBA reference manual is about 300 pages long. However, we have covered
the main points needed to begin Access VBA/DAO programming. (For a reference on the
VBA language, you might want to check out the topic VB & VBA in a Nutshell , by Paul
Lomax, also published by O'Reilly.)
Actually, many Access VBA programming tasks require only a small portion of VBA's
features, and you will probably find yourself wrestling much more with DAO's object
model than with the VBA language itself.
I conclude our discussion of the VBA language per se with a brief outline of topics for
further study, which you can do using the VBA help files .
 
Search WWH ::




Custom Search