Part II: Programming Microsoft Access
448
FIGURE 11.15
frmNamedArguments demonstrates the value of using named arguments in VBA procedures.
Examine the code in the following listing to see how named arguments work:
Private Sub cmdBackward_Click()
txtOutput = PrepareOutput(sStr2:=txtLastName, _
sStr3:=txtFirstName, sStr1:=txtHireDate)
End Sub
The thing to notice in cmdBackward_Click is that the arguments are not passed to
PrepareOutput() in the order specified by the procedure’s argument list. As long as the name
used for an argument matches an argument in PrepareOutputs’s argument list, Access VBA
correctly uses the arguments in PrepareOutput().
On the CD-ROM
The Chapter11.accdb example database includes the frmNamedArguments you see in Figure 11.15 and
Figure 11.16. The two buttons below the Function Output text box pass the text from the First Name, Last
Name, and Hire Date text boxes to the PrepareOutput() function using positional and named arguments.
FIGURE 11.16
PrepareOutput() is able to use arguments submitted in any order as long as they’re named.