本人初次接触ACCESS,做了一个客户管理的界面,但在修改这个按钮上出错,希望大家给予指正。万分感谢!
运行时弹出对话框:对象变量和with变量未设置
Private Sub 修改客户_Click()
On Error GoTo Err_修改客户_Click
Dim i As Integer
Dim stemp As String
Dim rs As ADODB.Recordset
stemp = "select * from 客户"
rs.Open stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If IsNull(Me![客户ID]) = True Then
MsgBox "请输入客户ID,此项不能为空!", vbOKOnly, "信息"
Me![客户ID].SetFocus
ElseIf IsNull(Me![客户名称]) = True Then
MsgBox "请输入客户名称,此项不能为空", vbOKOnly, "信息"
Me![客户名称].SetFocus
ElseIf IsNull(Me![客户地址]) = True Then
MsgBox "请输入客户地址,此项不能为空", vbOKOnly, "信息"
Me![客户地址].SetFocus
ElseIf IsNull(Me![客户性质]) = True Then
MsgBox "请输入客户性质,此项不能为空", vbOKOnly, "信息"
Me![客户性质].SetFocus
ElseIf IsNull(Me![客户类别]) = True Then
MsgBox "请输入客户类别,此项不能为空", vbOKOnly, "信息"
Me![客户类别].SetFocus
ElseIf IsNull(Me![级别]) = True Then
MsgBox "请输入级别,此项不能为空", vbOKOnly, "信息"
Me![级别].SetFocus
ElseIf IsNull(Me![联系人]) = True Then
MsgBox "请输入联系人,此项不能为空", vbOKOnly, "信息"
Me![联系人].SetFocus
ElseIf IsNull(Me![联系电话]) = True Then
MsgBox "请输入联系电话,此项不能为空", vbOKOnly, "信息"
Me![联系电话].SetFocus
ElseIf IsNull(Me![备注]) = True Then
MsgBox "请输入备注,此项不能为空", vbOKOnly, "信息"
Me![备注].SetFocus
ElseIf IsNull(Me![省]) = True Then
MsgBox "请输入省,此项不能为空", vbOKOnly, "信息"
Me![省].SetFocus
ElseIf IsNull(Me![市]) = True Then
MsgBox "请输入市,此项不能为空", vbOKOnly, "信息"
Me![市].SetFocus
Else
rs.MoveFirst
For i = 1 To rs.RecordCount
If rs("客户ID") = Me![客户ID] Then
rs("客户名称") = Me![客户名称]
rs("客户地址") = Me![客户地址]
rs("客户性质") = Me![客户性质]
rs("客户类别") = Me![客户类别]
rs("级别") = Me![级别]
rs("联系人") = Me![联系人]
rs("联系电话") = Me![联系电话]
rs("省") = Me![省]
rs("市") = Me![市]
rs("备注") = Me![备注]
rs.Update
MsgBox "修改完成!", vbOKOnly, "信息"
Exit Sub
Else
rs.MoveNext
End If
Next i
End If
Me![客户 子窗体].Requery
Set rs = Nothing
' DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_修改客户_Click:
Exit Sub
Err_修改客户_Click:
MsgBox Err.Description
Resume Exit_修改客户_Click
End Sub