'改用户名 conn.execute "update 表名 set 用户名字段='"& 新用户名变量 &"' where 用户名字段='"& 旧用户名变量 &"'" '改密码 conn.execute "update 表名 set 用户密码字段='"& 新密码 &"' where 用户名字段='"& 用户名变量 &"'"
'登录窗体: Option Explicit Dim pnum As Integer Private Sub XPButton1_Click() On Error GoTo finish '防错代码,防止意外而导致的退出 sql = "select * from 用户管理 where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "'" cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\data.mdb;Persist Security Info=False" cn.Open rs.CursorLocation = adUseClient rs.Open sql, cn, adOpenDynamic, adLockOptimistic '以上使用最通用的方法来查询数据库中是否有匹配的记录 If rs.EOF = True Then '如果没有记录则说明用户或密码为错误的 If pnum < 2 Then 'pnum就是密码验证次数,当次数超过3次,系统会自动保护退出 pnum = pnum + 1 MsgBox "用户名或密码错误!", vbInformation, "错误次数:" & pnum rs.Close cn.Close Text1.Text = "" Text2.Text = "" Text1.SetFocus Exit Sub Else MsgBox "用户名或密码错误超过三次,系统会自动退出", vbInformation, "提示" End End If Else loginname = rs.Fields(0) Form1.Show rs.Close cn.Close End If Exit Sub finish: MsgBox Err.Description rs.Close cn.Close End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then '获取按键,如果是回车就运行image_click按钮的内容 Call XPButton1_Click End If End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text2.SetFocus End If End Sub Private Sub XPButton2_Click() End End Sub Private Sub XPButton3_Click() frmZhuce.Show End Sub '注册窗体: Option Explicit Dim Password As String Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And Text1 <> "" Then sql = "select * from 用户管理 where 用户名='" & Text1.Text & "'" ' and 密码='" & Text2.Text & "'" cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\data.mdb;Persist Security Info=False" cn.Open rs.CursorLocation = adUseClient rs.Open sql, cn, adOpenDynamic, adLockOptimistic If rs.EOF = True Then '没有该用户名可以注册 MsgBox "用户名可以注册!" rs.Close cn.Close Newname = Text1.Text Text4 = Newname Text2.SetFocus Else MsgBox "该用户名已经存在,换名注册!" Text1.Text = "" Text1.SetFocus End If End If Exit Sub finish: MsgBox Err.Description End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And Text2 <> "" Then Password = Text2.Text Text5 = Password Text3.SetFocus End If End Sub Private Sub Text3_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And Text3.Text = Text2.Text Then XPButton3.Enabled = True XPButton3.SetFocus ElseIf KeyAscii = 13 And Text3.Text <> Text2.Text Then Text3 = "" Text3.SetFocus End If End Sub Private Sub XPButton1_Click() Unload Me End Sub 模块: Option Explicit Public loginname As String Public cn As New ADODB.Connection '定义数据库的连接存放数据和代码 Public rs As New ADODB.Recordset Public sql As String Public Newname As String 具体工程参阅: http://iask.sina.com.cn/b/14844871.html 的附件。
或者发到我邮箱 我帮你写好。
[email protected]
conn.execute "update 表名 set 用户名字段='"& 新用户名变量 &"' where 用户名字段='"& 旧用户名变量 &"'"
'改密码
conn.execute "update 表名 set 用户密码字段='"& 新密码 &"' where 用户名字段='"& 用户名变量 &"'"
'登录窗体:
Option Explicit
Dim pnum As Integer Private Sub XPButton1_Click()
On Error GoTo finish '防错代码,防止意外而导致的退出
sql = "select * from 用户管理 where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "'"
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\data.mdb;Persist Security Info=False"
cn.Open
rs.CursorLocation = adUseClient
rs.Open sql, cn, adOpenDynamic, adLockOptimistic
'以上使用最通用的方法来查询数据库中是否有匹配的记录
If rs.EOF = True Then '如果没有记录则说明用户或密码为错误的
If pnum < 2 Then 'pnum就是密码验证次数,当次数超过3次,系统会自动保护退出
pnum = pnum + 1
MsgBox "用户名或密码错误!", vbInformation, "错误次数:" & pnum
rs.Close
cn.Close
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Exit Sub
Else
MsgBox "用户名或密码错误超过三次,系统会自动退出", vbInformation, "提示"
End
End If
Else
loginname = rs.Fields(0)
Form1.Show
rs.Close
cn.Close
End If
Exit Sub
finish:
MsgBox Err.Description
rs.Close
cn.Close
End Sub Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then '获取按键,如果是回车就运行image_click按钮的内容
Call XPButton1_Click
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
End If
End Sub Private Sub XPButton2_Click()
End
End Sub Private Sub XPButton3_Click()
frmZhuce.Show
End Sub '注册窗体:
Option Explicit
Dim Password As String Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Text1 <> "" Then
sql = "select * from 用户管理 where 用户名='" & Text1.Text & "'" ' and 密码='" & Text2.Text & "'"
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\data.mdb;Persist Security Info=False"
cn.Open
rs.CursorLocation = adUseClient
rs.Open sql, cn, adOpenDynamic, adLockOptimistic
If rs.EOF = True Then '没有该用户名可以注册
MsgBox "用户名可以注册!"
rs.Close
cn.Close
Newname = Text1.Text
Text4 = Newname
Text2.SetFocus
Else
MsgBox "该用户名已经存在,换名注册!"
Text1.Text = ""
Text1.SetFocus
End If
End If
Exit Sub
finish:
MsgBox Err.Description
End Sub Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Text2 <> "" Then
Password = Text2.Text
Text5 = Password
Text3.SetFocus
End If
End Sub Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Text3.Text = Text2.Text Then
XPButton3.Enabled = True
XPButton3.SetFocus
ElseIf KeyAscii = 13 And Text3.Text <> Text2.Text Then
Text3 = ""
Text3.SetFocus
End If
End Sub Private Sub XPButton1_Click()
Unload Me
End Sub
模块:
Option Explicit
Public loginname As String
Public cn As New ADODB.Connection '定义数据库的连接存放数据和代码
Public rs As New ADODB.Recordset
Public sql As String
Public Newname As String 具体工程参阅:
http://iask.sina.com.cn/b/14844871.html
的附件。