changkhoonline77 > 20-09-13, 07:52 AM
MTNQ > 21-09-13, 03:08 AM
Private Sub cmdLUU_Click()
On Error GoTo cmdLUU_Err
If Me.NewRecord And Not Me.Dirty Then
MsgBox "Ban phai nhap du lieu truoc khi luu", , "Luu Y!"
txtTEN.SetFocus
Exit Sub
End If
DoCmd.RunCommand acCmdSaveRecord
DoCmd.SetWarnings False
If Nz(DLookup("MSNV", "Table2", "MSNV = " & Me.txtMSNV & ""), 0) = 0 Then
DoCmd.RunSQL "INSERT INTO Table2 SELECT * FROM Table1 WHERE ((Table1.MSNV)=[Forms]![frmTable1]![txtMSNV]);"
Else
DoCmd.RunSQL "UPDATE Table1 INNER JOIN Table2 ON Table1.MSNV = Table2.MSNV SET Table2.TEN = Table1.TEN, Table2.TUOI = Table1.TUOI, Table2.DIACHI = Table1.DIACHI WHERE ((Table2.MSNV)=[Forms]![frmTable1]![txtMSNV]);"
End If
DoCmd.SetWarnings True
cmdTHEM.Enabled = True
cmdTHEM.SetFocus
cmdLUU.Enabled = False
cmdLUU_Exit:
Exit Sub
cmdLUU_Err:
MsgBox "Ma loi: " & Err.Number & Chr(13) & Err.Description, , "Loi"
Resume cmdLUU_Exit
End Sub
Private Sub Form_Close()
On Error GoTo FClose_Err
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO Table2 SELECT * FROM Table1 WHERE (Table1.MSNV Not In (select [MSNV] from [Table2]));"
DoCmd.SetWarnings True
FClose_Exit:
Exit Sub
FClose_Err:
MsgBox "Ma loi: " & Err.Number & Chr(13) & Err.Description, , "Loi"
Resume FClose_Exit
End Sub
danhxetnghiem > 23-05-14, 02:24 PM