例如,要往某个表(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作者: partz 时间: 2010-6-18 18:49
然后在设计视图里,找到你要做双击事件的控件,写下鼠标双击事件代码:
Private Sub ID_DblClick(CANCEL As Integer)
Dim strFilter As String
strFilter = "ID = " & Me.ID
DoCmd.OpenForm "窗体A", acFormNormal, , strFilter
End Sub
其实就是做个筛选条件。当然,前提是你已经做好这个要打开的“窗体A”。