1
ห้อง MS Access / : อยากให้แสดงตัวเลข เศษที่่เหลือรวมในงวดสุดท้าย และ วันที่ตามกำหนดดิวครับ
« เมื่อ: 01 เม.ย. 64 , 10:36:50 »
ถ้าเท่ากันทุกงวดงั้นโค๊ดจะเป็นแบบนี้


โค๊ด: [Select]
Private Sub Command0_Click()
Dim rs As DAO.Recordset
Dim i As Integer
Dim getMonth As String
Dim getYear As String
Dim getDate As String
Dim getTotal As Long
Dim getPay As Long
Dim getPayMonth As Long
Dim getLastpay As Long
Dim getInterest As Long
Set rs = CurrentDb.OpenRecordset("Table1", dbOpenDynaset)
getTotal = 98000 'ส่วนที่จะสร้าง textbox ระบุยอดเงิน
getDate = "5" 'ส่วนที่จะสร้าง textbox กำหนดวันที่ชำระ
getMonth = DatePart("m", Date)
getYear = DatePart("yyyy", Date)
getPay = (getTotal) / 36
getPayMonth = getTotal
Do Until i > 36
For i = 1 To 36
getMonth = getMonth
If getMonth > 12 Then
getYear = getYear + 1
getMonth = "1"
Else
getYear = getYear
End If
'---------------เพิ่มเรคคอร์ดใหม่--------------
rs.AddNew
'ใส่ชื่อฟิลด์ที่ต้องการ และใส่ค่า โดยกำหนด Data Type ให้ถูกต้อง ถ้าเป็น Text ต้องมี "" คล่อม ถ้าเป็นตัวเลขไม่ต้องมี
rs!รหัส = "001"
rs!ชื่อสินค้า = "งวดที่ " & i
rs!วันครบกำหนด = CDate(getDate & "/" & getMonth & "/" & getYear)
If i = 36 Then
rs!จำนวน = getPayMonth
Else
rs!จำนวน = getPay
End If
rs!ดอกเบี้ย = (((getTotal * 15) / 100) / 12)
rs.Update
getMonth = getMonth + 1
getPayMonth = getPayMonth - getPay
Next i
Loop
'-----------------------------------------
rs.Close: Set rs = Nothing
End Sub
โพสต์นี้ได้รับคำขอบคุณจาก: assetthai