Question

The problem

enter image description here

In the following form i want to accomplish two things

  • When Post check box is ticked i.e. when post= true a query should run targeting the current record only and subtracting the amount with balance field in the customer table.

    UPDATE Customer INNER JOIN [Loan Payment] ON Customer.CUSID = [Loan Payment].CUSID SET Customer.CUSBalance = [Customer]![CUSBalance]-[Forms]![Loan Payment]![Amount] WHERE (((Customer.CUSID)=[Forms]![Loan Payment]![CUSID]));

BUT INSTEAD THE WHEN THE QUERY IS EXECUTED FOR EXAMPLE ON LP6 INSTEAD OF [BALANCE]-20 IT DOES BALANCE-110 i.e. THE QUERY IS RUNNING ON ALL FIELDS

  • When the query have ran and post has been changed to true the post check box of the current record should become disabled so that the query may not ran twice or more times

AND I FOUND THAT CONDITIONAL FORMATTING CANNOT BE APPLIED TO TEXT BOXES

Requirement

  1. I would like to know if i can achieve what i want and how?
  2. Any workaround or alternative solution to what i am currently trying to achiee.
Was it helpful?

Solution

Firstly, I was using the wrong SQL.

UPDATE Customer SET Customer.CUSBalance = [Customer]![CUSBalance]-[Forms]![Loan Payment]![Amount]
WHERE (((Customer.CUSID)=[Forms]![Loan Payment]![CUSID]));

Secondly I found that conditional formatting can not be applied to check boxes so I had to find a workaround and I found three.

work around 1

I locked the Post check box and introduced a button which if Post = false would run the query and make Post = True

MY FORM NOW

MY FORM NOW

The Code I used on the post button [on click procedure]

Private Sub Command19_Click()

If Me.Post = False Then
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "updateCustomerLoan"
    DoCmd.SetWarnings True
    Me.Post = True
    MsgBox ("Record has been Posted")
ElseIf Me.Post = True Then
    MsgBox ("Record has already been posted")
End If

End Sub

Work around 2

I applied the following code on post_update() where I wrote two queries one do query (update) and one undo query (update)

Private Sub Post_AfterUpdate()
    If Me.Post = True Then
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "payLoanONpost"
        DoCmd.SetWarnings True
        MsgBox ("The record has been posted")
    ElseIf Me.Post = False Then
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "unpayLoanONunpost"
        DoCmd.SetWarnings True
        MsgBox ("Record has been unposted")
    End If
End Sub

Work around 3 (by far the best and does what I initially set out to do

Here I only used one update query

Private Sub Post_AfterUpdate()
    If Me.Post = True Then
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "payLoanONpost"
        DoCmd.SetWarnings True
        MsgBox ("The record has been posted")
    ElseIf Me.Post = False Then
        MsgBox ("The record cannot unposted")
        Me.Post = True
    End If
End Sub

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top