回复 2楼 lowxiong
已经赋值了,下边是连接数据库的代码和登录按钮的代码,数据库连接是在模块里,麻烦帮我看一下
Public cnn As New ADODB.Connection '新建一个数据源
Public qy1 As New ADODB.Recordset '数据一个记录集
Public qy2 As New ADODB.Recordset '数据一个记录集
Sub Main()
tkOpenAccessDB App.Path & "\MIS.mdb" '连接数据库
If qy1.State = adStateOpen Then '表状态
qy1.Close
End If
qy1.Open "select * from 密码表", cnn, adOpenStatic, adLockReadOnly, adCmdText '查询表内是否有数据
If qy1.RecordCount = 0 Then
Set qy1 = cnn.Execute("insert into 密码表 values('admin','admin','经理')") '表内无数据执行此语句新建用户
End If
登录Frm.Show
End Sub
Private Sub tkOpenAccessDB( _
tkFileName As String, _
Optional tkUserID As String, _
Optional tkPassword As String _
) '连接数据库参数
On Error GoTo tkFinish
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & tkFileName & ";" & _
"Mode=Share Deny None;" & _
"Extended Properties=;" & _
"Jet OLEDB:System database=;" & _
"Jet OLEDB:Registry Path=;" & _
"Jet OLEDB:Database Password=;" & _
"Jet OLEDB:Engine Type=5;" & _
"Jet OLEDB:Database Locking Mode=1;" & _
"Jet OLEDB:Global Partial Bulk Ops=2;" & _
"Jet OLEDB:Global Bulk Transactions=1;" & _
"Jet OLEDB:New Database Password=;" & _
"Jet OLEDB:Create System Database=False;" & _
"Jet OLEDB:Encrypt Database=False;" & _
"Jet OLEDB:Don't Copy Locale on Compact=False;" & _
"Jet OLEDB:Compact Without Replica Repair=False;" & _
"Jet OLEDB:SFP=False;" & _
tkUserID, _
tkPassword
Exit Sub
tkFinish:
MsgBox Err.Description
End
End Sub
这是登录按钮的程序
程序代码:
Private Sub Command1_Click()
On Error GoTo finish
User = Text1.Text
Set mdbrs = cnn.Execute("select * from 密码表 where 用户名称='" & Text1.Text & "' and 密码='" & Text2.Text & "'")
If mdbrs.EOF = True Then
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
MsgBox "用户名和密码不正确!!"
Else
user111 = mdbrs.Fields(0)
sup = mdbrs.Fields(2)
If mdbrs.Fields(2) = "经理" Then
chair = True
End If
If mdbrs.Fields(2) = "管理员" Then
workman = True
End If
If mdbrs.Fields(2) = "客户" Then
cust = True
End If
Unload Me
MDIForm1.Show
End If
Exit Sub
finish:
MsgBox Err.Description
End Sub