DooHoaangPhuuc > 19-09-18, 12:55 AM
duynamvnn1208 > 19-09-18, 08:08 AM
bằng lăng > 19-09-18, 09:13 AM
tranthanhan1962 > 19-09-18, 06:51 PM
Private Sub Xoarecord_Click()
On Error GoTo Biloi
DoCmd.RunCommand acCmdDeleteRecord
Biloi:
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim n_Reply As Integer
Response = acDataErrContinue
n_Reply = msgBox("Ban muon xoa record nay", vbQuestion + vbYesNo, "Thong Bao")
If n_Reply = vbNo Then
Cancel = True
End If
End Sub
DooHoaangPhuuc > 20-09-18, 10:14 PM
ongke0711 > 21-09-18, 10:31 AM
yamakashi2003 > 17-05-20, 02:18 AM
(19-09-18, 06:51 PM)tranthanhan1962 Đã viết: Code xử lý xóa record:Bác cho em hỏi là câu lệnh cancel = true dùng như thế nào ạ,
Giả sử bạn có một nút lệnh xóa record tên là Xoarecord
ở event form Form_BeforeDelConfirm (tam dịch trước khi xác nhận xóa)Mã:Private Sub Xoarecord_Click()
On Error GoTo Biloi
DoCmd.RunCommand acCmdDeleteRecord
Biloi:
End Sub
Ở msgBox nếu bạn yes record sẽ bị xóa nếu bạn no hành động xóa sẽ được bỏ qua. Lệnh Response = acDataErrContinue tắt cảnh báo cảnh báo của access "you are about to delete record(s)" và thay thế bằng thông báo của n_Reply, muốn thông báo bằng tiếng việt bạn có thể dùng hàm msgBoxUni đã có hướng dẫn trên forrumMã:Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim n_Reply As Integer
Response = acDataErrContinue
n_Reply = msgBox("Ban muon xoa record nay", vbQuestion + vbYesNo, "Thong Bao")
If n_Reply = vbNo Then
Cancel = True
End If
End Sub
tranthanhan1962 > 17-05-20, 11:15 AM
(17-05-20, 02:18 AM)yamakashi2003 Đã viết: Bác cho em hỏi là câu lệnh cancel = true dùng như thế nào ạ,Cái tên nói lên bản chất. exit sub: thoát khỏi thủ tục, ngưng tất cả mọi lệnh và đi nhậu
nó có giống như là exit sub không ạ
Em xin cảm ơn
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim n_Reply As Integer
Response = acDataErrContinue
n_Reply = msgBox("Ban muon xoa record nay", vbQuestion + vbYesNo, "Thong Bao")
If n_Reply = vbNo Then
Cancel = True
End If
Docmd.OpenForm "ABC"
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim n_Reply As Integer
Response = acDataErrContinue
n_Reply = msgBox("Ban muon xoa record nay", vbQuestion + vbYesNo, "Thong Bao")
If n_Reply = vbNo Then
Exit Sub
End If
Docmd.OpenForm "ABC"
End Sub
yamakashi2003 > 17-05-20, 05:42 PM
(17-05-20, 11:15 AM)tranthanhan1962 Đã viết:Bác cho em hỏi trong đoạn code này:(17-05-20, 02:18 AM)yamakashi2003 Đã viết: Bác cho em hỏi là câu lệnh cancel = true dùng như thế nào ạ,Cái tên nói lên bản chất. exit sub: thoát khỏi thủ tục, ngưng tất cả mọi lệnh và đi nhậu
nó có giống như là exit sub không ạ
Em xin cảm ơn. Cancel = True/False, ngưng hoặc thực hiện 1 lệnh nào đó, tiếp tục thực hiện các lệnh khác, nếu có.
Trong mã trên Cancel là tham số của lệnh xóa, mã này xử lý trường hợp. Có nghĩ là nếu chọn nút [No] trên thông báo nó sẽ hủy lệnh xóa, nếu không (chọn nút yes) thì ngược lại Cancel = False => thực lệnh xóa (chỉ xử lý cho lệnh này)