| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 535 人关注过本帖
标题:求助: 实时错误‘91’对象变量或 With 块变量没有设置
只看楼主 加入收藏
alpha07
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-5-26
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
求助: 实时错误‘91’对象变量或 With 块变量没有设置
     本机测试正常,打包也正常,到另外机器安装成功后,首次运行就出现:实时错误‘91’对象变量或 With 块变量没有设置
请高手指点一下是哪出问题,万分感谢~~
1、登陆窗口代码:
Private Sub cmdOK_Click()
    Dim txtSQL As String
    Dim mrc As ADODB.Recordset
    Dim MsgText As String
    'ToDo: create test for correct password
    'check for correct password
   
      UserName = ""
    If Trim(txtUserName.Text = "") Then
        MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
        txtUserName.SetFocus
    Else
        txtSQL = "select * from user_Info where user_ID = '" & txtUserName.Text & "'"
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        If mrc.EOF = True Then
            MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
            txtUserName.SetFocus
        Else
            If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
                OK = True
                mrc.Close
                Me.Hide
                UserName = Trim(txtUserName.Text)
            Else
                MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
                txtPassword.SetFocus
                txtPassword.Text = ""
            End If
        End If
    End If
   
    miCount = miCount + 1
    If miCount = 3 Then
        Me.Hide
    End If
    Exit Sub
End Sub

2、SQL ExecuteSQL相关代码如下

Public Function ConnectString() _
   As String
'returns a DB ConnectString
   ConnectString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Student;Data Source=MZX"
End Function
Public Function ExecuteSQL(ByVal SQL _
   As String, MsgString As String) _
   As ADODB.Recordset
'executes SQL and returns Recordset
   Dim cnn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Dim sTokens() As String
   
   On Error GoTo ExecuteSQL_Error
   
   sTokens = Split(SQL)
   Set cnn = New ADODB.Connection
   cnn.Open ConnectString
   
   If InStr("INSERT,DELETE,UPDATE", _
      UCase$(sTokens(0))) Then
      cnn.Execute SQL
      MsgString = sTokens(0) & _
         " query successful"
   Else
      Set rst = New ADODB.Recordset
      rst.CursorLocation = adUseClient
      rst.Open Trim$(SQL), cnn, _
         adOpenKeyset, _
         adLockOptimistic
      'rst.MoveLast     'get RecordCount
      Set ExecuteSQL = rst
      MsgString = "查询到" & rst.RecordCount & _
         " 条记录 "
   End If
ExecuteSQL_Exit:
   Set rst = Nothing
   Set cnn = Nothing
   Exit Function
   
ExecuteSQL_Error:
   MsgString = "查询错误: " & _
      Err.Description
   Resume ExecuteSQL_Exit
End Function

Public fMainForm As frmMain
Public UserName As String


Sub Main()
    Dim fLogin As New frmLogin
    fLogin.Show vbModal
    If Not fLogin.OK Then
        'Login Failed so exit app
        End
    End If
    Unload fLogin


    Set fMainForm = New frmMain
    fMainForm.Show
End Sub
搜索更多相关主题的帖子: With 变量 实时 对象 
2010-05-27 16:26
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:20 
上次是你问过这段代码吗?
是没处理错误造成的.
        txtSQL = "select * from user_Info where user_ID = '" & txtUserName.Text & "'"
        Set mrc = ExecuteSQL(txtSQL, MsgText)

这二句后面要进行错误判断
        If MsgText <> "" Then
            MsgBox MsgText, vbCritical
            End
        End If

然后根据提示加以处理.




授人于鱼,不如授人于渔
早已停用QQ了
2010-05-27 19:18
快速回复:求助: 实时错误‘91’对象变量或 With 块变量没有设置
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017270 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved