Work around Ms Access continuous form?

只愿长相守 提交于 2020-01-06 10:42:07

问题


The problem

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.

回答1:


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

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



来源:https://stackoverflow.com/questions/22394573/work-around-ms-access-continuous-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!