รบกวนขอ Code ในการตัดค่าที่ไม่ซ้ำกับ Record ก่อนหน้าครับ

เริ่มโดย sirichai, 19 มิ.ย 18 , 11:30:12

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

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

sirichai

ยกตัวอย่างเช่น           --------->   อยากให้เป็นแบบนี้ครับ   
ครั้ง      ออม                                      ครั้ง      ออม                                         
1          5                                         1         5
2          7                                         2         7
3          1                                         3         1
4          2                                         4         2
5         12                                        5        12
6           2                                        6         2
7           2                                        9         0                                     
8           2                                        10       2
9           0
10         2


ขอรบกวนท่านผู้รู้ด้วยนะครับ :prettiness:
  •  

ปิ่นณรงค์

อ้างถึงจาก: sirichai ใน 19 มิ.ย 18 , 11:30:12
ยกตัวอย่างเช่น           --------->   อยากให้เป็นแบบนี้ครับ   
ครั้ง      ออม                                      ครั้ง      ออม                                         
1          5                                         1         5
2          7                                         2         7
3          1                                         3         1
4          2                                         4         2
5         12                                        5        12
6           2                                        6         2
7           2                                        9         0                                     
8           2                                        10       2
9           0
10         2


ขอรบกวนท่านผู้รู้ด้วยนะครับ :prettiness:
ตัวอย่างวางบน Module นะครับ

Public Function DeleteIFDuplicate
Dim db As DAO.Database
Dim recIn As DAO.Recordset
Dim strSaving As String
Dim lngRecordsDeleted As Long
lngRecordsDeleted = 0
Set db = CurrentDb()
Set recIn = db.OpenRecordset("Query1")
If recIn.EOF Then
    MsgBox ("No Input Records")
    recIn.Close
    Set recIn = Nothing
    Set db = Nothing
    Exit Function
End If
Do
If recIn!saving = strSaving Then
   recIn.Delete
   lngRecordsDeleted = lngRecordsDeleted + 1
Else
    strSaving = recIn!saving
   
End If
recIn.MoveNext
Loop Until recIn.EOF
recIn.Close
Set recIn = Nothing
Set db = Nothing
MsgBox ("You Deleted " & lngRecordsDeleted & " Records")
End Function




หมายเหตุ Field Saving คือ Field ที่ชื่อ ออม นะครับ

Query1 คือชื่อ Query ที่เราต้องการ ที่ผมกำหนดจากคิวรี่ เพราะต้องการเรียง Round จากน้อยไปหามากก่อน
การใช้งาน สร้างปุ่ม Command Botton มีอันนึง ที่ Event Onclick ใส่ไปว่า
Private Sub Command1_Click()
Call DeleteIFDuplicate
End Sub

:love: :grin:
  •  
    โพสต์นี้ได้รับคำขอบคุณจาก: sirichai

sirichai

  •