|
有一个窗体,窗体上有一个按钮,该按钮的代码如下,是用来向表中添加记录的,问题在于,每次打开这个窗体,它都好像在内存中生成一条空记录似的(这是本人猜想,不知道对不对),然后关闭此窗体时,这条记录就会保存在表中,形成一条空记录,即关闭窗体时保存了空记录。我找了很久都没找出问题出在哪里,请各位大侠指教,感激不尽,顺祝新年快乐,万事如意!
Private Sub 签到_Click()
On Error GoTo err_签到_Click
Dim STR As String
Dim rs As New ADODB.Recordset
STR = "select * from 签到总记录"
rs.Open STR, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If Me![姓名] <> "" And Me![联系电话] <> "" Then
With rs
.AddNew
![姓名] = Me![姓名]
![联系电话] = Me![联系电话]
![签到时间] = Now()
.Update
End With
MsgBox "签到成功,预祝你工作愉快", vbOKOnly, "签到成功"
Me![姓名] = Null
Me![联系电话] = Null
Me.姓名.SetFocus
DoCmd.OpenForm "当天记录 窗体"
Forms![当天记录 窗体].Requery
Else
MsgBox "你所填的信息不完整,请补充,谢谢你的配合", vbOKOnly, "警告"
Me![姓名].SetFocus
End If
rs.Close
Set rs = Nothing
Exit_签到_Click:
Exit Sub
err_签到_Click:
MsgBox Err.Description
Resume Exit_签到_Click
End Sub |
|