I have just really started looking at using VB to run main functions in my forms to ease up a bit of processing time. I used to have a sum which gave a total on screen for the selected customer but this would never write to the main table so i was unable to use it at a later date without having to run the calculation again - So i built this module below but the field it is meant to update only ever has '#Name?' in it - i have checked all names but just can seem to figure it out - the code is below:
Public Sub MyPaymentTotal()
On Error GoTo MyPaymentTotal_Err
Dim DetailRst As DAO.Recordset
Dim CurDB As 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(PubTotal)FROM Frm_Customer WHERE CustRef = Me.CustRef")
If Not DetailRst.EOF Then
PaymentTotal = Nz(DetailRst!DailyTotal, 0)
End If
DetailRst.Close
Me!Payments = PaymentTotal
MyPaymentTotal_Exit:
Exit Sub
MyPaymentTotal_Err:
MsgBox Err.Description
Resume MyPaymentTotal_Exit
End Sub
Any help greatly appreciated
Public Sub MyPaymentTotal()
On Error GoTo MyPaymentTotal_Err
Dim DetailRst As DAO.Recordset
Dim CurDB As 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(PubTotal)FROM Frm_Customer WHERE CustRef = Me.CustRef")
If Not DetailRst.EOF Then
PaymentTotal = Nz(DetailRst!DailyTotal, 0)
End If
DetailRst.Close
Me!Payments = PaymentTotal
MyPaymentTotal_Exit:
Exit Sub
MyPaymentTotal_Err:
MsgBox Err.Description
Resume MyPaymentTotal_Exit
End Sub
Any help greatly appreciated