Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for existence.

Status
Not open for further replies.

Petemush

Technical User
Jun 21, 2002
255
GB
I have a Procedure with an Optional argument. How can I check to see whether it has been passed or not?

Cheers,

Pete
 
When I use optional parameters, I always set them to a default value that I can trap... e.g.:

Public Function RunReport(CustomerID as Integer, Optional AsOfDate As Date = 0)

'The next line of code will set the variable 'AsOfDate' to todays date if the calling function didn't specify a date
If AsOfDate = 0 Then AsOfDate = Date

docmd.openreport Name:="CustomerReport",WhereCondition:="ReportDate = #" & AsOfDate & "#"

End Function
 
Thank You both,

The problem seems though, that IsMissing isn't working correctly.

To double check, I Dimmed a Boolean and set it to IsMissing(param_name) put a breakpoint in and checked the value of it when the procedure was called without the optional argument. It remained false. I submit the code in hope that I've done something wrong and you can correct it.

'Enables or disables controls on form frmFindCourses depending on
'the value of the control's corresponding CheckBox.

Public Sub After_Update_Checkboxes(checkbox_name As CheckBox, _
control_name As Control, _
Optional changeCost As String, _
Optional eqOp As OptionGroup)

Dim form1 As Form, test As Boolean, test2 As Boolean
Set form1 = Form_frmFindCourses

'If the CheckBox is ticked...
If checkbox_name = True Then

'...then enable the CheckBox's corresponding control.
control_name.Enabled = True
test = IsMissing(eqOp)
test2 = Not test
If test Then
eqOp.Enabled = True
End If

If Not IsMissing(changeCost) Then
If IsNull(form1![Cost Type]) Then

form1![CostType Check].Value = True
form1![Cost Type].Enabled = True
form1![Cost Type] = changeCost

End If
End If

Else

'Disable and clear the checkbox's corresponding control.
control_name.Enabled = False
control_name.Value = Null

If Not IsMissing(eqOp) Then
eqOp.Enabled = False
eqOp.Value = eqOp.DefaultValue
End If
End If

End Sub



This is the procedure that calls it.

Private Sub ArrangeBy_Check_AfterUpdate()

Call After_Update_Checkboxes([ArrangeBy Check], [Arranged By])

End Sub



Thanks in advance for any help,

Cheers,

Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top