ได้แล้วครับ ไป copy ผิดขั้นตอนไม่นึกว่าจะเป็นปัญหา
ใน ยูทูป เขาแบ่งสอน 4 สเตป ผมดันไปเอา สเตป 3 มาใช้
code ดั้งเดิม ในยูทูป
Code: Select all
Private Sub cmdDelete_Click()
If Selected_List = 0 Then
MsgBox "No row is selected.", vbOKOnly + vbInformation, "Delete"
Exit Sub
End If
Dim i As VbMsgBoxResult
i = MsgBox("Do you want to delete the selected record?", vbYesNo + vbQuestion, "Confirmation")
If i = vbNo Then Exit Sub
ThisWorkbook.Sheets("Database").Rows(Selected_List + 1).Delete
Call Reset
MsgBox "Selected record has been deleted.", vbOKOnly + vbInformation, "Deleted"
End Sub
ผมปรับมาใช้ของผมดังนี้
Code: Select all
Private Sub cmdDelete_Click()
Dim iRow As Long
If Selected_ListfrmBo = 0 Then
MsgBox "ท่านไม่ได้เลือกรายการใน List box.", vbOKOnly + vbInformation, "Delete"
Exit Sub
End If
Dim i As VbMsgBoxResult
i = MsgBox("ท่านต้องการ ลบ รายการที่ท่านเลือก ใช่หรือไม่ ?", vbYesNo + vbQuestion, "Confirmation")
If i = vbNo Then Exit Sub
ThisWorkbook.Sheets("Addrequisition1").Rows(Selected_ListfrmBo + 1).Delete
' iRow = Application.WorksheetFunction.Match(Me.ListBox2.List(Me.ListBox2.ListIndex, 0), _
' ThisWorkbook.Sheets("Addrequisition1").Range("B:B"), 0)
'
' ThisWorkbook.Sheets("Addrequisition1").Rows(iRow).Delete
Call ResetFormBorrow3
Me.ListBox2.ListIndex = -1 'ไม่โชว์แถบสีน้ำเงิน
MsgBox "ทำการ ลบ record ที่ท่านเลือกแล้ว", vbOKOnly + vbInformation, "Deleted"
txtADDNumber.Text = ListBox2.ListCount
End Sub
เรียนอาจารย์ครับ
' iRow = Application.WorksheetFunction.Match(Me.ListBox2.List(Me.ListBox2.ListIndex, 0), _
' ThisWorkbook.Sheets("Addrequisition1").Range("B:B"), 0)
'
' ThisWorkbook.Sheets("Addrequisition1").Rows(iRow).Delete
ที่อาจารย์บอกความหมายไว้ก่อนหน้านี้ ดูเหมือนจะเกี่ยวกับการ del คือ
เมื่อลบข้อมูลใน listbox แล้วให้ลบบรรทัดใน sheet ที่เกียวข้องกัน listbox
code ด้านบน น่าจะหมายถึงแบบนี้
คำถาม
สรุปว่าถ้าไม่มี code 3 บรรทัดบน นี้ การ เกี่ยวกับการ add หรือ del ไหมครับ
ขอบคุณมากครับ