本窗体代码优化的是输入原密码才可以更改密码,在更改密码之后退出主窗体,重新登陆
逻辑图
修改密码的界面
本窗体代码
Option Explicit
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim txtSQL, MsgText As String
Dim mrc As ADODB.Recordset
If txtMypwd.Text = "" Then
MsgBox "请输入原密码!"
Else
If txtPassword1.Text = "" Or txtPassword2.Text = "" Then
MsgBox "请输入新密码"
Else
If txtMypwd.Text = txtPassword1.Text Or txtMypwd.Text = txtPassword2.Text Then
MsgBox "原密码和新密码相同"
Else
If Trim(txtPassword1.Text) <> Trim(txtPassword2.Text) Then
MsgBox "两次密码不一样!", vbOKOnly + vbExclamation, "警告"
txtPassword1.SetFocus
txtPassword1.Text = ""
Else
txtSQL = "select*from user_info where user_ID='" & UserName & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
mrc.Fields(1) = txtPassword1.Text
mrc.Update
mrc.Close
MsgBox "密码修改成功!", vbOKOnly + vbExclamation, "修改密码"
Unload Me
Unload fMainForm
'重新打开登陆窗体和Main窗体
Dim fLogin As New frmLogin
fLogin.Show vbModal
If Not fLogin.OK Then
End
End If
Unload fLogin
fMainForm.Show
End If
End If
End If
End If
txtPassword1.Text = ""
txtPassword2.Text = ""
txtMypwd.Text = ""
End Sub
如果大家有什么更加简便的代码和有需要优化的部分,可以在下面回复我,进行讨论。