toidjtjmtoi > 08-11-19, 02:19 PM
Trích dẫn:Private Sub Form_BeforeUpdate(Cancel As Integer)
WriteChanges
End Sub
Public Function WriteChanges()
Dim frm As Form
Dim ctl As Control
Dim frmname As String, user As String, sql As String, changes As String
Dim db As DAO.Database
Set frm = Screen.ActiveForm
Set db = CurrentDb
frmname = Screen.ActiveForm.Name
user = hamlaytenthat()
changes = ""
sql = "INSERT INTO tblUpdate " & _
"([NgayCapNhat],[FormCapNhat], [NguoiCapNhat], [TinhHinhCapNhat]) " & _
"VALUES (#" & Now & "#,'" & frmname & "', '" & user & "', "
For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup
If IsNull(ctl.OldValue) And Not IsNull(ctl.Value) Then
changes = changes & _
ctl.Name & "--" & "BLANK" & "--" & ctl.Value & _
vbCrLf
ElseIf IsNull(ctl.Value) And Not IsNull(ctl.OldValue) Then
changes = changes & _
ctl.Name & "--" & ctl.OldValue & "--" & "BLANK" & _
vbCrLf
ElseIf ctl.Value <> ctl.OldValue Then
changes = changes & _
ctl.Name & ": " & ctl.OldValue & "--> " & ctl.Value & _
vbCrLf
End If
End Select
Next ctl
sql = sql & "'Thaydoi :" & changes & " ');"
db.Execute sql, dbFailOnError
Set frm = Nothing
Set db = Nothing
End Function
ongke0711 > 08-11-19, 03:43 PM
toidjtjmtoi > 08-11-19, 03:57 PM
ongke0711 > 08-11-19, 04:16 PM
toidjtjmtoi > 09-11-19, 09:13 PM
ongke0711 > 11-11-19, 12:24 AM
(08-11-19, 05:47 PM)toidjtjmtoi Đã viết:(08-11-19, 04:16 PM)ongke0711 Đã viết: Có đưa vô sự kiện BeforeUpdate của Subform chưa?
Pro cho mình xin file demo được không . Mình thử rồi nó báo lỗi không nhận ra
(09-11-19, 09:13 PM)toidjtjmtoi Đã viết: Mong mọi người trợ giúp ạ
dotrung > 12-04-20, 12:54 PM
ongke0711 > 12-04-20, 01:07 PM
Xuân Thanh > 12-04-20, 02:30 PM