I'm trying to replace a value in a query from an event procedure in a form (afterupdate). I enter a deposit amount, then I select the invoice this is for via a form. I then open up a query on all unpaid invoices. This query shows the total bill, the amount paid to date, and a check box for when the invoice is paid. I then search for the invoice I selected from the drop down box, read in the total bill, then compare the payment to see if more money is still owing, if it's paid, or if they have overpaid. Then, depending on the results, I replace the Amount Paid.
I can't get it to replace the amount in the query from the event procedure. Any help will be greatly appreciated. There is the code I have to date. The black text is what I am trying to do, and the blue text directly below is the working code. The red is where I don't know what to do.
'In form [Transactions – Deposits Subform] enter amount paid in box '[AmountSubform]
'Select the invoice number from [InvoiceNumber] dropdown box
'Execute “afterupdate” Event Procedure
'Read [AmountSubform] into variable [nowpaid]
Dim nowpaid As Currency
Dim searchrecord As Integer
nowpaid = Me!AmountSubform
'Read [InvoiceNumber] into variable [searchrecord]
searchrecord = Me!InvoiceNumber
'Open Query [Transactrions – Deposit Query]
DoCmd.OpenQuery ("Transactions – Deposit Query")
'Goto invoice number by using variable [searchrecord]
DoCmd.FindRecord searchrecord, acAnywhere, True, acSearchAll
'Read data from column [Total$] into variable [PaidTotoal]
PaidTotal = DLookup("Total$", "Transactions – Deposit Query", "QuoteID = " & Me!InvoiceNumber)
'Read data from column [AmtPaid] into variable [alreadypaid]
alreadypaid = DLookup("AmtPaid", "Transactions – Deposit Query", "QuoteID = " & Me!InvoiceNumber)
'Do check - If [alreadypaid] + [nowpaid] > [PaidTotal]
If (alreadypaid + nowpaid) > PaidTotal Then
'Return an Error saying an overpayment occurred
MsgBox "There is an error. Overpayment!"
'Close Query
DoCmd.Close
'Return to [AmountSubform] box in TransactionsDepositsSubform] Form
Me![AmountSubform].SetFocus
'End Statement
End If
'If [alreadypaid] + [nowpaid] = [PaidTotal]
If (alreadypaid + nowpaid) = PaidTotal Then
'Replace [AmtPaid] column of query with [PaidTotal] from [Total] column
THIS IS THE LINE I CAN"T FIGURE OUT
'Goto [Closed] column which is default of unchecked box 'and make it a check
THIS IS THE LINE I CAN"T FIGURE OUT Either
'End Statement
End If
If [alreadypaid] + [nowpaid] < [PaidTotal]
If (alreadypaid + nowpaid) < PaidTotal Then
Replace [AmtPaid] with the sum of [alreadypaid] + [nowpaid]
Endif
End If
Close Query
I can't get it to replace the amount in the query from the event procedure. Any help will be greatly appreciated. There is the code I have to date. The black text is what I am trying to do, and the blue text directly below is the working code. The red is where I don't know what to do.
'In form [Transactions – Deposits Subform] enter amount paid in box '[AmountSubform]
'Select the invoice number from [InvoiceNumber] dropdown box
'Execute “afterupdate” Event Procedure
'Read [AmountSubform] into variable [nowpaid]
Dim nowpaid As Currency
Dim searchrecord As Integer
nowpaid = Me!AmountSubform
'Read [InvoiceNumber] into variable [searchrecord]
searchrecord = Me!InvoiceNumber
'Open Query [Transactrions – Deposit Query]
DoCmd.OpenQuery ("Transactions – Deposit Query")
'Goto invoice number by using variable [searchrecord]
DoCmd.FindRecord searchrecord, acAnywhere, True, acSearchAll
'Read data from column [Total$] into variable [PaidTotoal]
PaidTotal = DLookup("Total$", "Transactions – Deposit Query", "QuoteID = " & Me!InvoiceNumber)
'Read data from column [AmtPaid] into variable [alreadypaid]
alreadypaid = DLookup("AmtPaid", "Transactions – Deposit Query", "QuoteID = " & Me!InvoiceNumber)
'Do check - If [alreadypaid] + [nowpaid] > [PaidTotal]
If (alreadypaid + nowpaid) > PaidTotal Then
'Return an Error saying an overpayment occurred
MsgBox "There is an error. Overpayment!"
'Close Query
DoCmd.Close
'Return to [AmountSubform] box in TransactionsDepositsSubform] Form
Me![AmountSubform].SetFocus
'End Statement
End If
'If [alreadypaid] + [nowpaid] = [PaidTotal]
If (alreadypaid + nowpaid) = PaidTotal Then
'Replace [AmtPaid] column of query with [PaidTotal] from [Total] column
THIS IS THE LINE I CAN"T FIGURE OUT
'Goto [Closed] column which is default of unchecked box 'and make it a check
THIS IS THE LINE I CAN"T FIGURE OUT Either
'End Statement
End If
If [alreadypaid] + [nowpaid] < [PaidTotal]
If (alreadypaid + nowpaid) < PaidTotal Then
Replace [AmtPaid] with the sum of [alreadypaid] + [nowpaid]
Endif
End If
Close Query