此代码是用来实现密码修改功能
Private Sub Command1_Click()
Dim username As String
Dim oldpassword As String
Dim newpassword As String
Dim cnn As New ADODB.Connection
Dim ret As New ADODB.Recordset
Dim local_db As String
'检查文本框是否为空
If Text1.Text = "" Then
MsgBox "请输入用户名", , "警告"
Text1.SetFocus
Else
If Text2.Text = "" Then
MsgBox "请输入旧密码", , "警告"
Text2.SetFocus
Else
If Text3.Text = "" Then
MsgBox "请输入新密码", , "警告"
Text3.SetFocus
Else
If Text4.Text = "" Then
MsgBox "请确认密码", , "警告"
Text4.SetFocus
End If
End If
End If
End If
If Text1.Text <> "" And Text2.Text <> "" _
And Text3.Text <> "" And Text4.Text <> "" Then
If Text3.Text <> Text4.Text Then
MsgBox "密码不一致", , "警告"
Text4.SetFocus
Else
Set cnn = New ADODB.Connection
Set ret = New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\xs.mdb;Persist Security Info=false" '连接数据库
username = Trim(Text1.Text)
oldpassword = Text2.Text
local_db = "select use from xs" + _
" where xs.use=" + "'" + username + "'"
ret.Open local_db, cnn
'检查用户是否存在
If ret.BOF And ret.EOF Then
MsgBox "系统中无此用户", , "警告"Text1.SetFocus '设置光标焦点
ret.Close
'检查密码是否正确
Else
ret.Close
local_db = "select use from xs" + _
" where xs.use=" + "'" + username + "' and" + _
" xs.password=" + "'" + oldpassword + "'"
ret.Open local_db, cnn
If ret.BOF And ret.EOF Then
MsgBox "旧密码不正确", , "警告"
Text2.SetFocus
ret.Close
Else
ret.Close
'修改密码
newpassword = Text3.Text
local_db = "update xs" + _
" set password=" + "'" + newpassword + "'" + _
" where xs.use=" + "'" + username + "'"
cnn.Execute local_db
MsgBox "密码修改成功!", , "提示"
'Form6.Hide
Unload Me
End If
End If
End If
End If
End Sub

解决方案 »

  1.   

    Private Sub cmdOK_Click()
        Dim StrSQL As String
        StrSQL = "select USERNAME,PSD from WORK where USERNAME= '" & Trim(TxtUserName.Text) & "'and PSD ='" & Md5_String_Calc(Trim(TxtForPWD.Text)) & "'"
        If Trim(TxtUserName.Text) <> Empty And Trim(TxtForPWD.Text) <> Empty And Trim(TxtNewPWD.Text) <> Empty Then
            If RsModPwd.State = adStateClosed Then
                RsModPwd.Open StrSQL, objCn, adOpenKeyset, adLockPessimistic, adCmdText   '//打开记录集
            End If
                If RsModPwd.RecordCount <> 0 Then          '//判断记录集中的记录是否等于零
                    RsModPwd.Fields(1).Value = Md5_String_Calc(Trim(TxtNewPWD.Text))
                    RsModPwd.Update                        '//更新记录集
                    MsgBox "密码修改成功", , "密码修改"
                    Unload Me
                Else
                    MsgBox "您的输入有误,请重新输入!", vbExclamation, "验证失败"
                    RsModPwd.Close
                End If
        Else
            MsgBox "请输入要修改的用户名及密码 ", vbInformation, "错误提示"
            'RsModPwd.Close
        End If
    End Sub
      

  2.   

    注意保留字:
    local_db = "update xs" + _
    " set [password]=" + "'" + newpassword + "'" + _
    " where xs.use=" + "'" + username + "'"