Gasman
Enthusiastic Amateur
- Local time
- Today, 19:46
- Joined
- Sep 21, 2011
- Messages
- 16,737
Hi all again, sorry for the amount of questions recently, but I seem to be hitting one stumbling block after another. :banghead:
I have a table tblStock Traded that holds stock info, stock name and date are the relevant fields.
I realised that in my DB, I was not showing the total amount for stock traded.
I tried using the form with a query that had the table linked to a group query but that made the form unupdatable.
So I created a UDF and that works fine, except for the fact that the (New) line that is shown in datasheets (I'm using another of those split forms) shows #Error
I tried surrounding the code with the ISNULL function, but it appears to make no difference? I'd rather see a zero in the control than #Error
Is there a way to suppress this #Error please?
I've also tried
=IIF(IsError(CommTotal([TradeDate],[Stock])),"",CommTotal([TradeDate],[Stock])) from a post in this forum, but could not get that to work either.
My code is as follows
TIA
I have a table tblStock Traded that holds stock info, stock name and date are the relevant fields.
I realised that in my DB, I was not showing the total amount for stock traded.
I tried using the form with a query that had the table linked to a group query but that made the form unupdatable.
So I created a UDF and that works fine, except for the fact that the (New) line that is shown in datasheets (I'm using another of those split forms) shows #Error
I tried surrounding the code with the ISNULL function, but it appears to make no difference? I'd rather see a zero in the control than #Error
Is there a way to suppress this #Error please?
I've also tried
=IIF(IsError(CommTotal([TradeDate],[Stock])),"",CommTotal([TradeDate],[Stock])) from a post in this forum, but could not get that to work either.
My code is as follows
Code:
Public Function CommTotal(pdtDate As Date, pstrStock As String)
Dim sngRate As Single
Dim CurTotal As Currency
' Get the rate from the tblStockTraded table
If Not IsNull(pdtDate) Then
sngRate = Nz(DLookup("CommRate", "tblStockTraded", "Stock='" & pstrStock & "' AND TradeDate = " & Format(pdtDate, strcJetDate)), 0) / 100
CurTotal = DSum("NetCost", "tblSVSTrades", "Stock='" & pstrStock & "' AND BuySell = 'Buy' AND TradeDate = " & Format(pdtDate, strcJetDate))
CommTotal = CurTotal * sngRate
Else
CommTotal = 0
End If
End Function
TIA