登录窗口“oper”无效
这是数据库的一个公共模块,进入系统共有个PASS窗体,用于输入用户名和密码
运行后,输入正确的用户名和密码,然后说:对象名“oper”无效,请教错在哪里,怎么改!多谢了~~~·
以下是模块代码:
Public userlevel As String '保存用户级别
Public flag As Integer
Public flag1 As Integer
Public num As Integer
Public condstr As String
Public recs As Integer
Public recs1 As Integer
Public tna As String
Public cap As String
Sub main() '主过程
pass.Show vbModal
End Sub
Public Function exesql(ByVal sql As String) As ADODB.Recordset
sql = Trim$(sql)
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
conn.ConnectionString = "provider=sqloledb;driver=(sql server);" + _
"server=WWW-D4CC14DD61C;uid=sa;pwd=xywnhy2005;database=wudianchangyong"
conn.Open
Set rst.ActiveConnection = conn
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.Open sql 运行后指向了这里
Set exesql = rst
Set rst = Nothing
Set conn = Nothing
End Function
Public Sub deldate(ByVal tn As String) '删除指定表中所有记录,对oper表添加一个系统用户
Dim sql As String
sql = "delete" & Trim$(tn)
Set conn = New ADODB.Connection
conn.ConnectionString = "provider=sqloledb;driver=(sql server);" + _
"server=WWW-D4CC14DD61C;uid=sa;pwd=xywnhy2005;database=wudianchangyong"
conn.Open
conn.Execute sql
If Trim(tn) = "oper" Then
sql = "insert oper values('1234','1234'.'系统管理员')"
conn.Execute sql
End If
conn.Close
End Sub
以下是PASS窗体部分代码:
Private Sub Command1_Click()
Dim mrc As ADODB.Recordset
txtsql = "select * from oper where 用户名='" & _
Trim$(Text1(0).Text) & "'" & "and 密码='" & Trim$(Text1(1).Text) + "'"
Set mrc = exesql(txtsql)
If mrc.RecordCount = 0 Then '未找到用户记录
n = n + 1
If n < 3 Then
MsgBox "没有这个用户,请确认登录信息后,继续尝试!", vbOKOnly + vbExclamation, "信息提示"
Text1(0).Text = " "
Text1(1).Text = " "
Text1(0).SetFocus
Else
MsgBox "超过3次未成功登录,推出系统", vbOKOnly + vbExclamation, "信息提示"
mrc.Close
Unload Me
End If
Else
userlevel = Trim(mrc.Fields("级别"))
mrc.Close
Unload Me
menu.Show '调用menu窗体
End If
End Sub