例如,要往某个表(tbl收据)里添加数据,做个窗体,再给个按钮保存(CmdSave),单击事件如下:
Private Sub CmdSave_Click()
Dim STemp As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "tbl收据", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
With rs
.AddNew
![日期] = Me.日期
![收据号] = Me.收据号
![公司名称] = Me.公司名称
![收款事由] = Me.收款事由
![金额] = Me.金额
.Update
End With
rs.Close
Set rs = Nothing
MsgBox "保存成功!", vbOKOnly, SoftName
End Sub