I'm trying to use an optional textbox object as an argument in a function but had some problems:
I got around them by declaring the argument as a Variant instead:
Then test for IsMissing(DateBox2). I'm curious, about one thing, though... If I use this code:
...then everything works perfectly. However, if I try to write the value directly to the DateBox2 variant, like this:
...the value of DateBox2 never gets back to the calling form. Can someone 'splain that to me? Thanks!
Ken S.
Code:
Public Sub OpenCalendarDateOnly(FormObj As Form, DateBox As TextBox, [blue]Optional DateBox2 As TextBox[/blue])
Code:
Public Sub OpenCalendarDateOnly(FormObj As Form, DateBox As TextBox, [blue]Optional DateBox2 As Variant[/blue])
Code:
If Not IsNull(p_dtSelected) Then
DateBox = Format(p_dtSelected, "m/d/yyyy")
If Not IsMissing(DateBox2) Then [green]'if DateBox2 argument has been passed[/green]
Set ctrl2 = DateBox2 [green]'assign DateBox2 variant to control variable[/green]
If Not IsDate(ctrl2) Then [green]'if ctrl2 does not hold a valid date[/green]
ctrl2 = Null [green]'set value to Null[/green]
ctrl2 = Format(p_dtSelected, "m/d/yyyy") [green]'write date value[/green]
DateBox2 = ctrl2 [green]'assign ctrl2 value to DateBox2 variant[/green]
End If
End If
DateBox.SetFocus
End If
Code:
If Not IsNull(p_dtSelected) Then
DateBox = Format(p_dtSelected, "m/d/yyyy")
If Not IsMissing(DateBox2) Then [green]'if DateBox2 argument has been passed[/green]
If Not IsDate(DateBox2) Then [green]'if DateBox2 does not hold a valid date[/green]
[blue]DateBox2 = Null[/blue] [green]'set value to Null[/green]
[blue]DateBox2 = Format(p_dtSelected, "m/d/yyyy")[/blue] [green]'write date value[/green]
End If
End If
DateBox.SetFocus
End If
Ken S.