[Quote=引用 3 楼 get_red_rocket 的回复:]
Dim tim As Integer '设置窗体级变量,记录密码输入次数
Dim pin As Integer '用户输入次数
Public mark As String '登陆的用户名
Dim myval As String '设置窗体级变量
Private Sub Command1_Click()
Dim fm As String
Dim pstr As String
Dim tim As Integer '设置窗体级变量,记录密码输入次数
Dim pin As Integer '用户输入次数
Public mark As String '登陆的用户名
Dim myval As String '设置窗体级变量
Private Sub Command1_Click()
Dim fm As String
Dim pstr As String
fm = "d:\" & "用户管理数据库\" & "用户管理数据库.mdb"
pstr = "provider=microsoft.jet.oledb.4.0;" '不能写成3.51
pstr = pstr & "data source=" & fm
With frmlogin.Adodc1
.ConnectionString = pstr
.CommandType = adCmdText
.RecordSource = "select * from " & "用户管理数据表"
End With
Set DataGrid1.DataSource = Adodc1
Dim s, s1, s2 As Integer
If Adodc1.Recordset.RecordCount = 0 Then
Else
Adodc1.Recordset.MoveFirst
End If
For s1 = 1 To Adodc1.Recordset.RecordCount
If Text1.Text = Adodc1.Recordset.Fields(0).Value Then
mark = Text1.Text
s = s + 1
If s = 1 Then
Text3.Text = Adodc1.Recordset.Fields(1).Value
End If
End If
Adodc1.Recordset.MoveNext
Next s1
If s = 1 Then
If Text3.Text = Text2.Text Then
exit sub
Else
MsgBox "密码错误,请重试", vbInformation, "登录" '显示警示信息
tim = tim + 1
If tim = 3 Then
MsgBox "输入错误次数过多,退出", vbExclamation, "登录系统"
Unload Me
End If
End If
ElseIf s = 0 Then
MsgBox "无此用户", vbInformation, "登录"
pin = pin + 1
If pin = 3 Then
MsgBox "输入错误次数过多,退出", vbExclamation, "登录系统"
Unload Me
End If
Else
MsgBox "用户名不唯一,请重试!", vbInformation, "登录"
End If
End Sub
'--------------可以从网上搜一下,我这只是我一个笨办法。
用户管理数据库格式是
用户名 密码 用户权限
user 123 管理员
阿明 aming 客户
森 12 一般操作人员
'---------------
这种例子网上很多,可以根据自己需要进行改进。
希望能帮到你!