ต้องการดึงข้อมูลรายการก่อนหน้ามาครับ

เริ่มโดย Wisarut007, 07 ก.ย 23 , 11:14:34

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

Wisarut007

สวัสดีครับ ขอสอบถามวิธีการ Query

- ต้องการดึงข้อมูลรายการก่อนหน้า ให้ออกมาตามคอลัมน์ Amount_New ตามตัวอย่างครับ

  •  

nonc31

Function updateAmountNew()
   On Error GoTo erC

        Dim db As Database
        Dim rstOut As Recordset
        Dim f As Field
        Dim taw As String
            Set db = CurrentDb
            Set rstOut = CurrentDb.OpenRecordset("ตาราง/คิวรี่")
           
        rstOut.MoveFirst
        Do Until rstOut.EOF
            If InStr(rstOut.Fields("DebitCredit").Value, "Credit") > 0 Then
                taw = rstOut.Fields("Amount").Value
            End If
        For Each f In rstOut.Fields
            DoCmd.SetWarnings False
            rstOut.Edit
            rstOut![AmountNew] = taw
            rstOut.Update
        Next
            rstOut.MoveNext
            If InStr(rstOut.Fields("DebitCredit").Value, "Credit") <= 0 Then
                taw = taw
            Else
                taw = rstOut.Fields("Amount").Value
            End If
        Loop
       
            rstOut.Close
            Set db = Nothing

Exit Function

erC:
    Select Case Err
        Case 0
        Case 3021
            Exit Function
        Case Else
            MsgBox "Function updateAmountNew" & " > " & Err.Description & " รหัส " & Err.Number
    End Select
End Function
  •