kutieu2016 > 15-04-17, 07:46 AM
ongke0711 > 15-04-17, 03:30 PM
Option Explicit
[/font]
Public Function GetRecord(rst As DAO.Recordset, frm As Form)
Dim fld As Field
Dim ctl As Control
For Each fld In rst.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
ctl = rst.Fields("" & fld.Name & "").Value
ElseIf ctl.Name = "img" & fld.Name Then
If Not IsNull(rst.Fields("" & fld.Name & "").Value) Then
'On Error Resume Next'
ctl.Picture = CStr(rst.Fields("" & fld.Name & "").Value)
End If
End If
Next
Next
End Function
Public Function AddRecord(rst As DAO.Recordset, frm As Form)
Dim fld As Field
Dim ctl As Control
rst.AddNew
For Each fld In rst.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
rst.Fields("" & fld.Name & "").Value = ctl
End If
Next
Next
rst.Update
End Function
Public Function UpdateRecord(rst As DAO.Recordset, frm As Form)
Dim fld As Field
Dim ctl As Control
rst.Edit
For Each fld In rst.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
rst.Fields("" & fld.Name & "").Value = ctl
End If
Next
Next
rst.Update
End Function
Public Sub ClearRecord(frm As Form)
Dim ctl As Control
For Each ctl In frm.Controls
If ctl.Tag Like "no" Then
'do nothing'
Else
Select Case ctl.ControlType
Case acTextBox, acComboBox, acCheckBox
ctl.Value = ""
Case acImage
ctl.Picture = ""
Case Else
'do nothing'
End Select
End If
Next
[font=Tahoma]End Sub
kutieu2016 > 15-04-17, 09:13 PM