不知道这个代码错在哪

来源:百度知道 编辑:互助问答吧 时间:2021/04/12 23:22:48
我是先定义一个模块cub main(),通过模块.在模块里用
If frmlogin.A Then
与登陆界面做连接的form所定义的公共变量A做连接,
如果满足数据库abc.mdb条件就进入下一个窗体,但我运行后他显示错误
错误是:[Microsoft][ODB驱动程序管理器]未发现数据源名称并且未指定默认驱动程序 失时错误-214746259 (80004005)'
我代码是:Public A As Boolean
Private Sub Form_Load()
A = False
End Sub
Private Sub cmdOK_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strUserID$, strPassword$, strSQL$
Static count As Byte
strUserID = Replace(Trim(txtUserName.Text), "'", "")
strPassword = Replace(Trim(txtPassword.Text), "'", "")
If strUserID = "" Then
MsgBox "用户名不能为空,请输入用户名", , "登陆错误"
txtUserName.SetFocus
Exit Sub
ElseIf strPassword = "" Then
MsgBox "密码不能为空,请输入用户名", , "登陆错误"
tetPassword.SetFocus
Exit Sub
End If
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
strSQL = "select * from Users where UesrID='" & strUserID & "'"
strSQL = strSQL & "AND Password='" & strPassword & "';"
conn.Open connstring
rs.Open strSQL, conn
If rs.EOF Then
count = count + 1
MsgBox "用户名不存在!", , "登陆失败"
txtUserName.Text = ""
txtPassword.Text = ""
txtUserName.SetFocus
Else
A = True
UserID = strUserID
UserName = rs("UserName").Value
Me.Hide
End If
re.Close
Set rs = Nothing
Set vconn = Nothing
If connt >= 3 Then
MsgBox "超过登陆次数,无权登陆!", , "登陆失败"
End
End If
End Sub
模块代码是:Option Explicit
Public connstring$, UserName$, UserID$

Sub Main()
connstring = "DRIVER=Microsoft Access Driver(*.mdb);DBQ=" & App.Path & "\samsung.mdb"
frmlogin.Show vbModal
If frmlogin.A Then
indexwindows.Show
Unload frmlogin
Else
MsgBox "无权登陆!!", , "登陆"
End
End If
End Sub
不知道哪里错了