ongke0711 > 19-04-17, 12:17 PM
Private Sub cmdLuu_Click()
Set db = CurrentDb
If Me.txtMaPCTC = "" Or IsNull(Me.txtMaPCTC) Then
MsgBoxUni "B" & ChrW(7841) & "n ph" & ChrW(7843) & "i nh" & ChrW(7853) & "p Mã ph" & ChrW(7909) & " c" & ChrW(7845) & "p.", vbCritical, "Thông báo"
Me.txtMaPCTC.SetFocus
Exit Sub
End If
If Me.cboNhomPCTC = "" Or IsNull(Me.cboNhomPCTC) Then
MsgBoxUni "B" & ChrW(7841) & "n ph" & ChrW(7843) & "i ch" & ChrW(7885) & "n Nhóm ph" & ChrW(7909) & " c" & ChrW(7845) & "p.", vbCritical, "Thông báo"
Me.cboNhomPCTC.SetFocus
Exit Sub
End If
If Me.txtTenPCTC = "" Or IsNull(Me.txtTenPCTC) Then
MsgBoxUni "B" & ChrW(7841) & "n ph" & ChrW(7843) & "i nh" & ChrW(7853) & "p Tên ph" & ChrW(7909) & " c" & ChrW(7845) & "p.", vbCritical, "Thông báo"
Me.txtTenPCTC.SetFocus
Exit Sub
End If
On Error GoTo cmdLuu_Err
Select Case strArgsArray(0)
Case "Add"
Set rs = db.OpenRecordset("tblMaPhuCap", dbOpenDynaset)
Call AddRecord(rs, Me)
Case "Edit"
Call UpdateRecord(rs, Me)
End Select
MsgBoxUni ChrW(272) & "ã l" & ChrW(432) & "u thông tin Mã ph" & ChrW(7909) & " c" & ChrW(7845) & "p.", vbInformation, "Thông báo"
Forms!frmDMPhuCap!sfmDMPhuCap.Requery
DoCmd.Close acForm, "frmMaPhuCap"
cmdLuu_Click_Exit:
Exit Sub
cmdLuu_Err:
Select Case Err.Number
Case 3022
MsgBoxUni "Mã ph" & ChrW(7909) & " c" & ChrW(7845) & "p này " & ChrW(273) & "ã t" & ChrW(7891) & "n t" & ChrW(7841) & "i.", vbCritical, "Thông báo"
Case Else
MsgBox Error$
End Select
Resume cmdLuu_Click_Exit
rs.Close
Set rs = Nothing
db.Close
End Sub
Public Sub AddRecord(rs As DAO.Recordset, frm As Form)
On Error GoTo ErrorHandler
Dim fld As Field
Dim ctl As control
rs.AddNew
For Each fld In rs.Fields
For Each ctl In frm.Controls
If ctl.Name = "txt" & fld.Name Or ctl.Name = "cbo" & fld.Name Or ctl.Name = "chk" & fld.Name Then
rs.Fields("" & fld.Name & "").Value = ctl
End If
Next
Next
rs.Update
ErrorHandler:
If Err.Number = 3022 Then
MsgBox "Du lieu da ton tai."
ElseIf Err.Number = 13 Then
MsgBox "Nhap sai kieu du lieu.Vd: Ban nhap du lieu dang Number vao Field dang Text."
Else
MsgBox Error$
End If
End Sub
tranthanhan1962 > 19-04-17, 01:55 PM
ongke0711 > 19-04-17, 05:32 PM
tranthanhan1962 > 19-04-17, 05:49 PM
(19-04-17, 05:32 PM)ongke0711 Đã viết: Ôi trời...vậy mà em mất nguyên đêm ngồi xem tới xem lui lỗi chính tả, có sai vị trí, logic gì không mà vẫn bó tay tới giờ. Chắc để tạo csdl mới import nó xem còn lỗi nữa không.
ongke0711 > 19-04-17, 06:06 PM
maidinhdan > 12-05-17, 07:10 PM
Public Sub AddRecord(rs As DAO.Recordset, frm As Form)
On Error GoTo Loi
Dim fld As Field
Dim ctl As control
rs.AddNew
For Each fld In rs.Fields
For Each ctl In frm.Controls
If ctl.Name = "txt" & fld.Name Or ctl.Name = "cbo" & fld.Name Or ctl.Name = "chk" & fld.Name Then
rs.Fields("" & fld.Name & "").Value = ctl
End If
Next
Next
rs.Update
LoiExit:
Exit Sub
Loi:
If Err.Number = 3022 Then
MsgBox "Du lieu da ton tai."
ElseIf Err.Number = 13 Then
MsgBox "Nhap sai kieu du lieu.Vd: Ban nhap du lieu dang Number vao Field dang Text."
Else
Resume LoiExit
End If
End Sub