HI
I finally got a function to sort of work but cant understand why it is doing certain things
the idea is that it calculates the total of Pubprice and then inserts it into the TestPayment field.
Now the function only works on the first customer on the comp screen but when you change to another customer it doesnt make any changes. I've tried putting it in the OnCurrent event but that just kicks up an error!
My code is:
Public Function MyPaymentTotal() As Double
On Error GoTo MyPaymentTotal_Err
Dim DetailRst As DAO.Recordset
Dim CurDB As DAO.Database
Dim PaymentTotal As Currency
Set CurDB = CurrentDb
PaymentTotal = 0
' open read only recordset to total up all amounts
Set DetailRst = CurDB.OpenRecordset("Select Sum(Tbl_PublicationNew.PubPrice)As DailyTotal FROM [Tbl_PublicationNew] WHERE [Tbl_PublicationNew]![CustRef] = " & [Forms]![Frm_Customer]![CustRef])
If Not DetailRst.EOF Then
PaymentTotal = Nz(DetailRst!DailyTotal, 0)
End If
DetailRst.Close
Forms![Frm_Customer]![testPayment] = PaymentTotal
MyPaymentTotal_Exit:
Exit Function
MyPaymentTotal_Err:
MsgBox Err.Description
Resume MyPaymentTotal_Exit
End Function
Any help at all would be greatly appreciated
Kind Regards
Simon
I finally got a function to sort of work but cant understand why it is doing certain things
the idea is that it calculates the total of Pubprice and then inserts it into the TestPayment field.
Now the function only works on the first customer on the comp screen but when you change to another customer it doesnt make any changes. I've tried putting it in the OnCurrent event but that just kicks up an error!
My code is:
Public Function MyPaymentTotal() As Double
On Error GoTo MyPaymentTotal_Err
Dim DetailRst As DAO.Recordset
Dim CurDB As DAO.Database
Dim PaymentTotal As Currency
Set CurDB = CurrentDb
PaymentTotal = 0
' open read only recordset to total up all amounts
Set DetailRst = CurDB.OpenRecordset("Select Sum(Tbl_PublicationNew.PubPrice)As DailyTotal FROM [Tbl_PublicationNew] WHERE [Tbl_PublicationNew]![CustRef] = " & [Forms]![Frm_Customer]![CustRef])
If Not DetailRst.EOF Then
PaymentTotal = Nz(DetailRst!DailyTotal, 0)
End If
DetailRst.Close
Forms![Frm_Customer]![testPayment] = PaymentTotal
MyPaymentTotal_Exit:
Exit Function
MyPaymentTotal_Err:
MsgBox Err.Description
Resume MyPaymentTotal_Exit
End Function
Any help at all would be greatly appreciated
Kind Regards
Simon