ledangvan > 01-05-18, 11:51 AM
MTNQ > 01-05-18, 03:12 PM
Private Sub SaoChepDL()
On Error GoTo Err_Handler
Dim strSql As String
Dim lngID As Long
If Me.Dirty Then
DoCmd.RunCommand acCmdSaveRecord
End If
If Me.NewRecord Then
MsgBox "Chua co du lieu de sao chep."
Else
With Me.Recordset.Clone
.AddNew
!SoCT = Me.SoCT
!NgayCT = Me.NgayCT
!Diengiai = Nz(Me.Diengiai, "")
!Donvi = Me.Donvi
.Update
.Bookmark = .LastModified
lngID = !HDID
If Me.[Chuyendoi Subform].Form.Recordset.Clone.RecordCount > 0 Then
strSql = "INSERT INTO Chuyendoi(HDID, MSTK,Sotien,NoCo,Nhanvien) " & _
"SELECT " & lngID & " As NewID,MSTK,Sotien,NoCo,Nhanvien " & _
"FROM [Chuyendoi] WHERE HDID = " & Me.HDID & ";"
'MTNQ chi lam vi du vai field thoi, ban them cac truong can sao chep vao nhe
CurrentDb.Execute strSql, dbFailOnError
Else
'MsgBox "Chua co du lieu chuyen doi."
End If
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description, , "SaoChepDL"
Resume Exit_Handler
End Sub
ledangvan > 06-04-22, 10:10 PM
(01-05-18, 03:12 PM)MTNQ Đã viết: Thủ tục sao chép dữ liệu trên main form + sub form nó tương tự như sau
Mã:Private Sub SaoChepDL()
On Error GoTo Err_Handler
Dim strSql As String
Dim lngID As Long
If Me.Dirty Then
DoCmd.RunCommand acCmdSaveRecord
End If
If Me.NewRecord Then
MsgBox "Chua co du lieu de sao chep."
Else
With Me.Recordset.Clone
.AddNew
!SoCT = Me.SoCT
!NgayCT = Me.NgayCT
!Diengiai = Nz(Me.Diengiai, "")
!Donvi = Me.Donvi
.Update
.Bookmark = .LastModified
lngID = !HDID
If Me.[Chuyendoi Subform].Form.Recordset.Clone.RecordCount > 0 Then
strSql = "INSERT INTO Chuyendoi(HDID, MSTK,Sotien,NoCo,Nhanvien) " & _
"SELECT " & lngID & " As NewID,MSTK,Sotien,NoCo,Nhanvien " & _
"FROM [Chuyendoi] WHERE HDID = " & Me.HDID & ";"
'MTNQ chi lam vi du vai field thoi, ban them cac truong can sao chep vao nhe
CurrentDb.Execute strSql, dbFailOnError
Else
'MsgBox "Chua co du lieu chuyen doi."
End If
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description, , "SaoChepDL"
Resume Exit_Handler
End Sub
MTNQ chỉ làm ví dụ vài trường thôi, bác nhớ thêm các trường cần sao chép vào nhé
ledangvan > 17-04-22, 12:02 AM