Xin chào toàn thể anh chị em.
Mình có 1 form nhập liệu có các text box và check box như sau:
Text box: txtGiatriPO, txtTonggiatriPOcoVAT, txtDongtienthanhtoan, txtSotiencanthanhtoanVND, txtSotiencanthanhtoanUSD, ......
và 1 check box: cboxVAT_TU.
Mình muốn viết sự kiên cho check box: cboxVAT_TU để tính số tiền cho 2 tex box: txtSotiencanthanhtoanVND, txtSotiencanthanhtoanUSD
với các điều kiện như sau:
Nếu txtDongtienthanhtoan = "VND" thì txtSotiencanthanhtoanUSD = 0
Nếu txtDongtienthanhtoan = "VND" và txtTamung = “Da thanh toan” và txtThanhtoanL1 = “Da thanh toan” và txtThanhtoanL2 = “Da thanh toan” và txtThanhtoanL3 = “Da thanh toan” thì txtSotiencanthanhtoanVND = 0
Nếu txtDongtienthanhtoan = "VND" và txtTamung = “Da thanh toan” và txtThanhtoanL1 = “Da thanh toan” và txtThanhtoanL2 = “Da thanh toan” và txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotienthanhtoanL3VND
...... cư lần lượt như vậy. Mình đã viết đoạn mã VBA sau mà không tính được, nhờ anh chị em xem giúp
Private Sub cboxVAT_TU_Click()
If txtDongtienthanhtoan = "VND" And cboxVAT_TU = True Then
txtSotientamungVND = txtTonggiatriPOcoVAT * txtGiatriphantramtamung
txtSotientamungUSD = 0
ElseIf txtDongtienthanhtoan = "VND" And cboxVAT_TU = False Then
txtSotientamungVND = txtGiatriPO * txtGiatriphantramtamung
txtSotientamungUSD = 0
Else
If txtDongtienthanhtoan <> "VND" And cboxVAT_TU = True Then
txtSotientamungUSD = txtTonggiatriPOcoVAT * txtGiatriphantramtamung
txtSotientamungVND = 0
ElseIf txtDongtienthanhtoan <> "VND" And cboxVAT_TU = False Then
txtSotientamungUSD = txtGiatriPO * txtGiatriphantramtamung
txtSotientamungVND = 0
End If
If txtDongtienthanhtoan = "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 = “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanVND = 0
End If
If txtDongtienthanhtoan = "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 = “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotienthanhtoanL3VND
End If
If txtDongtienthanhtoan = "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 = “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotienthanhtoanL2VND + txtSotienthanhtoanL3VND
End If
If txtDongtienthanhtoan = "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotienthanhtoanL1VND + txtSotienthanhtoanL2VND + txtSotienthanhtoanL3VND
End If
If txtDongtienthanhtoan = "VND" And txtTamung <> “Da thanh toan” And txtThanhtoanL1 = “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotientamungVND
End If
If txtDongtienthanhtoan = "VND" And txtTamung <> “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotientamungVND + txtSotienthanhtoanL1VND
End If
If txtDongtienthanhtoan = "VND" And txtTamung <> “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotientamungVND + txtSotienthanhtoanL1VND + txtSotienthanhtoanL2VND
End If
If txtDongtienthanhtoan = "VND" And txtTamung <> “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotientamungVND + txtSotienthanhtoanL1VND + txtSotienthanhtoanL2VND + txtSotienthanhtoanL3VND
End If
If txtDongtienthanhtoan = "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotienthanhtoanL1VND + txtSotienthanhtoanL2VND
End If
If txtDongtienthanhtoan = "VND" And txtDongtienthanhtoan = "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanVND = txtSotienthanhtoanL1VND + txtSotienthanhtoanL3VND
End If
If txtDongtienthanhtoan <> "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 = “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanUSD = 0
End If
If txtDongtienthanhtoan <> "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 = “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanUSD = txtSotienthanhtoanL3VND
End If
If txtDongtienthanhtoan <> "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 = “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanUSD = txtSotienthanhtoanL2VND + txtSotienthanhtoanL3VND
End If
If txtDongtienthanhtoan <> "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanUSD = txtSotienthanhtoanL1VND + txtSotienthanhtoanL2VND + txtSotienthanhtoanL3VND
End If
If txtDongtienthanhtoan <> "VND" And txtTamung <> “Da thanh toan” And txtThanhtoanL1 = “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanUSD = txtSotientamungVND
End If
If txtDongtienthanhtoan <> "VND" And txtTamung <> “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanUSD = txtSotientamungVND + txtSotienthanhtoanL1VND
End If
If txtDongtienthanhtoan <> "VND" And txtTamung <> “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanUSD = txtSotientamungVND + txtSotienthanhtoanL1VND + txtSotienthanhtoanL2VND
End If
If txtDongtienthanhtoan <> "VND" And txtTamung <> “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanUSD = txtSotientamungVND + txtSotienthanhtoanL1VND + txtSotienthanhtoanL2VND + txtSotienthanhtoanL3VND
End If
If txtDongtienthanhtoan <> "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 <> “Da thanh toan” And txtThanhtoanL3 = “Da thanh toan” Then
txtSotiencanthanhtoanUSD = txtSotienthanhtoanL1VND + txtSotienthanhtoanL2VND
End If
If txtDongtienthanhtoan <> "VND" And txtTamung = “Da thanh toan” And txtThanhtoanL1 <> “Da thanh toan” And txtThanhtoanL2 = “Da thanh toan” And txtThanhtoanL3 <> “Da thanh toan” Then
txtSotiencanthanhtoanUSD = txtSotienthanhtoanL1VND + txtSotienthanhtoanL3VND
End If
End If
End Sub