• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7. VBA: An Introduction > Passing Parameters and Returning Values

Passing Parameters and Returning Values

Both subroutines and functions can receive arguments (parameters), but only functions can return values. The following subroutine (found under the Pass Parameters command button of the frmParametersAndReturnValues form) receives two parameters, txtFirst and txtLast. It then displays a message box with the first character of each of the parameters that was passed.

Private Sub cmdPassParameters_Click()
  Call Initials(Nz(Me.txtFirstName.Value), Nz(Me.txtLastName.Value))
End Sub

Sub Initials(strFirst As String, strLast As String)
' This procedure can be found by selecting General in
' the Object drop-down list in the VBE window
  MsgBox "Your Initials Are: " & Left$(strFirst, 1) _
   & Left$(strLast, 1)
End Sub


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint