I have a form wherein there's a text box whose ControlSource is the function "=Position()". While I understand one can set the text box to NUll, one cannot set the ControlSource property to NUll. The function code is below. As I have it now, I simply trap the invalid use of null and let the text box be blank, as desired. However, I have the idea that there's a more appropriate method that should be put into practice?
Thoughts please.
Thanks,
Bill
Code:
Public Function Position() As Variant
Dim WhereExp As String
On Error GoTo PositionErr
If Me.InvstID <> 0 Then
WhereExp = "InvstID = " & Me.InvstID & " AND TTypeID = 1"
TotalBasis = DSum("[Basis]", "Ledgers", WhereExp)
SharesOwned = DSum("[Shares]", "Ledgers", "InvstID = " & Me.InvstID)
' Current Position, based on current value provided by Yahoo Finance
If SharesOwned > 0 Then
Position = (Me.PriceQuote * SharesOwned) - TotalBasis
Else
Position = Null
End If
Else
Position = Null
End If
ExitPosition:
Exit Function
PositionErr:
If Err.Number <> 94 Then _
MsgBox "Error number " & Err.Number & ": " & Err.Description
Resume ExitPosition
End Function