ADOCD 操作数据出错
各位老师下面是我写的修改数据库账号和密码的程序,请看看 ADODC1 操作数据库的地方,怎么老是不对,写成 .Recordset.Update 就报错“对象变量或 With 块变量未设置”,如果改为 .Refresh ,又报错为: “对象关闭时,不允许操作”,但是能成功修改数据,新手一直搞不懂原因,
望老师指点迷津:
1、为什么会提示 对象变量或 With 块变量未设置?
2、后面的写法也报错,为什么能修改数据呢?
3、怎么写才正确呢?
谢谢!
Private Sub Done_command_Click()
Dim NewPassWord As String
With Label4
If Old_Text.Text = Employee.PassWord Then
If New1_Text.Text = New2_Text.Text Then
If Len(New1_Text) >= 5 Then
NewPassWord = New1_Text.Text
With Adodc1
.RecordSource = "update tb_IDPW set PassWord='" & NewPassWord & "' where Name='" & Employee.Name & "'"
.Recordset.Update
End With
Employee.PassWord = NewPassWord
MsgBox "密码修改成功,新密码为:" & NewPassWord, vbInformation + vbOKOnly
Unload ChangePW_Form
Else
.ForeColor = &HFF&
.Caption = "新密码不能为空"
End If
Else
.ForeColor = &HFF&
.Caption = "两次新密码不一致!"
End If
Else
.ForeColor = &HFF&
.Caption = "旧密码输入错误!"
End If
End With
End Sub