Hi, I'm learning how to pass arguments to public functions and subs when pressing a button.
For my function this works fine, but when I try to execute a sub, I get error message:
Compile error: Argument not optional.
I know the problem lies in button call, because going through the sub with F8 executes it properly.
I've tried putting some arguments in the button call, but then I get a syntax error.
Halp!
This is the code for buttons:
Code:
Private Sub Command25_Click()
Module1.fIntroFunction
End Sub
Private Sub Command26_Click()
Module1.Starter
End Sub
Module1 contents:
Code:
Option Compare Database
Public Function fIntroFunction()
Dim lngLength As Long
Dim lngWidth As Long
Dim lngHeight As Long
lngLength = 150
lngWidth = 75
lngHeight = 50
MsgBox "Volume of space: " & FormatNumber(fCalculateVolume(lngLength, lngWidth, lngHeight), 0) & _
" Cubic Feet"
End Function
Private Function fCalculateVolume(lngLen, lngWdth, lngHgt) As Long
fCalculateVolume = (lngLen * lngWdth * lngHgt)
End Function
Private Sub Jumper()
Dim current As Date
Dim owner As String
current = Now()
owner = CurrentUser()
Call Starter(current, owner)
End Sub
Public Sub Starter(first As Date, second As String)
MsgBox "Date passed to Starter: " & first & vbCrLf & _
"Current User Name passed to Starter(): " & second
End Sub