แสดงกระทู้

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - sirichai

หน้า: [1]
1
ยกตัวอย่างเช่น           --------->   อยากให้เป็นแบบนี้ครับ   
ครั้ง      ออม                                      ครั้ง      ออม                                         
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 ใส่ไปว่า
โค๊ด: [Select]
Private Sub Command1_Click()
Call DeleteIFDuplicate
End Sub
โพสต์นี้ได้รับคำขอบคุณจาก: sirichai

หน้า: [1]