Hi,
I am trying to sum up a list of invoiced items (data stored in table tblInvoiceDetail) and write this value to the “Total” field in the table tblInvoices. I want this to update after each record is typed in the subform. I was given the below code from friend, but neither of us can get it working. Everytime we change a value in the subform, we get the error “Run-time error ‘3464’; Data type mismatch in critical expression”. Any idea of where I am going wrong? Or can you give me code that I can use?
Private Sub Form_AfterUpdate()
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT tblInvoiceDetail.INoID, Sum(tblInvoiceDetail.Total) as SumOfTotal FROM tblInvoiceDetail GROUP BY tblInvoiceDetail.INoID HAVING (((tblInvoiceDetail.INoID)='" & Form_frmInvoices.INoID & "'));")
Form_frmInvoices.txtTotal = rst!SumOfTotal
End Sub
I am trying to sum up a list of invoiced items (data stored in table tblInvoiceDetail) and write this value to the “Total” field in the table tblInvoices. I want this to update after each record is typed in the subform. I was given the below code from friend, but neither of us can get it working. Everytime we change a value in the subform, we get the error “Run-time error ‘3464’; Data type mismatch in critical expression”. Any idea of where I am going wrong? Or can you give me code that I can use?
Private Sub Form_AfterUpdate()
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT tblInvoiceDetail.INoID, Sum(tblInvoiceDetail.Total) as SumOfTotal FROM tblInvoiceDetail GROUP BY tblInvoiceDetail.INoID HAVING (((tblInvoiceDetail.INoID)='" & Form_frmInvoices.INoID & "'));")
Form_frmInvoices.txtTotal = rst!SumOfTotal
End Sub