运行EXE文件登录时出现这个问题,在别人电脑上就有这个问题。我的没有``是不是没有装VB
(别人的代码。看不是很懂。麻烦帮我改下吧~~~~)Private Sub Command1_Click()
'用来存放SQL语句
    Dim txtSQL As String
'用来存放记录集对象
    Dim mrc As New ADODB.Recordset
'用来存放返回信息
    Dim MsgText As String
    UserName = ""
'判断输入用户名是否为空
    If Trim(Text1.Text = "") Then
        MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
        Text1.SetFocus
    Else
        '查询指定用户名记录
        txtSQL = "select * from user_Info where user_ID='" & Text1.Text & "'"
        '执行查询语句
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        'mrc.Open
        If mrc.EOF = True Then
             MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
             Text1.SetFocus
        Else
            '判断输入密码是否正确
            If Trim(mrc.Fields(1)) = Trim(Text2.Text) Then
            Me.Hide
                OK = True
                mrc.Close
                
                UserName = Trim(Text1.Text)
                frmMain.Show
            Else
                MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
                Text2.SetFocus
                Text2.Text = ""
            End If
        End If
    End If
    '记载输入密码次数
    miCount = miCount + 1
    If miCount = 3 Then

解决方案 »

  1.   

    Private   Sub   Command1_Click() 
    '用来存放SQL语句 
            Dim   txtSQL   As   String 
    '用来存放记录集对象 
            Dim   mrc   As   New   ADODB.Recordset 
    '用来存放返回信息 
            Dim   MsgText   As   String 
            UserName   =   " " 
    '判断输入用户名是否为空 
            If   Trim(Text1.Text   =   " ")   Then 
                    MsgBox   "没有这个用户,请重新输入用户名! ",   vbOKOnly   +   vbExclamation,   "警告 " 
                    Text1.SetFocus 
            Else 
                    '查询指定用户名记录 
                    txtSQL   =   "select   *   from   user_Info   where   user_ID= ' "   &   Text1.Text   &   " ' " 
                    '执行查询语句 
                    Set   mrc   =   ExecuteSQL(txtSQL,   MsgText) 
                    'mrc.Open 
                    If   mrc.EOF   =   True   Then 
                              MsgBox   "没有这个用户,请重新输入用户名! ",   vbOKOnly   +   vbExclamation,   "警告 " 
                              Text1.SetFocus 
                              mrc.Close 
                    Else 
                            '判断输入密码是否正确 
                            If   Trim(mrc.Fields(1))   =   Trim(Text2.Text)   Then 
                            Me.Hide 
                                    OK   =   True 
                                    mrc.Close 
                                    
                                    UserName   =   Trim(Text1.Text) 
                                    frmMain.Show 
                            Else 
                                    MsgBox   "输入密码不正确,请重新输入! ",   vbOKOnly   +   vbExclamation,   "警告 " 
                                    Text2.SetFocus 
                                    Text2.Text   =   " " 
                                    mrc.Close                         End   If 
                    End   If 
            End   If 
            '记载输入密码次数 
            miCount   =   miCount   +   1 
            If   miCount   =   3   Then红色为添加部分
    试试
      

  2.   

    好像还是没用啊再帮我想想吧。。.
    运行EXE文件登录时出现这个问题,在别人电脑上就有这个问题。我的没有``是不是没有装VB 
      

  3.   


    If   Trim(Text1.Text   =   "")   Then 
    很奇怪,是不是 If   Trim(Text1.Text)   =   ""   Then 
    还有你仔细看看yangao 的代码
      

  4.   

    1.这里错了Trim(Text1.Text   =   " ")  ,应该是这个 Trim(Text1.Text)2。Set   mrc   =   ExecuteSQL(txtSQL,   MsgText)
    你在别人机器上的数据里面可能没有存储登陆信息,也就是你找不到任何返回值,没准返回了一个nothing,后面就会提示你这里错了
    你在自己的机器上把数据库清空看看  
      

  5.   

    不知道。。别人电脑上装了VB就可以用了把VB删了就不行了为什么啊。。我都快烦死了。。
      

  6.   

    把数据库转换成了 2003 的,换了些数据
     我的电脑都不行了。出错。。
    If   mrc.EOF   =   True   Then 
    就这句不行。对像关闭。什么什么的  
      

  7.   

            If Trim(Text1.Text) = "" Then
                    MsgBox "没有这个用户,请重新输入用户名", vbOKOnly + vbExclamation, "警告 "
                    Text1.SetFocus
            Else
                    '查询指定用户名记录
                    txtSQL = "select   *  from   user_Info   where   user_ID=  '" & Text1.Text & "' "
                    '执行查询语句
                    Set mrc = ExecuteSQL(txtSQL, MsgText)
                    'mrc.Open
                    If mrc.EOF = True Then
                              MsgBox "没有这个用户,请重新输入用户名", vbOKOnly + vbExclamation, "警告 "
                              Text1.SetFocus
                              mrc.Close
                    Else
                            '判断输入密码是否正确
                            If Trim(mrc.Fields(1)) = Trim(Text2.Text) Then
                                    Me.Hide
                                    OK = True
                                    mrc.Close
                                    
                                    UserName = Trim(Text1.Text)
                                    frmMain.Show
                            Else
                                    MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告 "
                                    Text2.SetFocus
                                    Text2.Text = ""                        End If
                    End If
            End If改到最后就是这样。还是不行。数据库换了。。没用
    装了VB都不行了
    If mrc.EOF = True Then   //这行提示
      

  8.   


    Text2.SetFocus
    Text2.Text = ""
    mrc.close
    忘加上了
    还有哪里不对吗。/
      

  9.   

     首先,如果你的VB程序,在其他没有安装VB的机器上用,必须安装其运行库
    把下边代码里涉及到的找到,连同你的VB程序一起拷贝到目标计算机上,然后
    写个批处理文件,代码如下,在目标机器运行批处理即可
    RegSvr32.exe /s comdlg32.ocx
    RegSvr32.exe /s MSADODC.OCX
    RegSvr32.exe /s mscomct2.ocx
    RegSvr32.exe /s mscomctl.ocx
    RegSvr32.exe /s MSDATGRD.OCX
    RegSvr32.exe /s comcat.dll
    RegSvr32.exe /s MSSTDFMT.DLL
    RegSvr32.exe /s MSFLXGRD.OCX其次,你连接数据库, 应该先做个连接啊,否则当然是提示你 对象关闭了
    Call getConnection("(Local)", "数据库名") 连接SQL 数据库
    Call OpenCnn  '连接Access数据库
    '打开SQL数据库
    Public Sub getConnection(ByVal strRunServer As String, ByVal strCatalog As String, _
                                    Optional strUserID As String = "sa", Optional strPwd As String = "")
    On Error GoTo err11
        
        If cn.State = adStateOpen Then
           cn.Close
        End If
        
        
        If strRunServer <> "" Then
            cn.ConnectionString = "Provider=SQLOLEDB;Data Source=" & strRunServer & ";" & _
                    "Initial Catalog=" & strCatalog & ";User Id=" & strUserID & ";Password=" & strPwd
            cn.CursorLocation = adUseClient
            cn.Open
        End If
        Exit Sub
    err11:
      'Stop
    End Sub
    '打开Access数据库
    Public Function OpenCnn()
    On Error GoTo err_line
      
      File_NameS = App.path + "\data\" + DataNames
      If Dir$(File_NameS) = "" Then
         MsgBox "系统文件夹:" + App.path + "\data 中 数据库文件(" + DataNames + ")不存在!", vbCritical + vbOKOnly, "数据库访问失败"
         End
      End If
      If cn.State <> adStateOpen Then
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + File_NameS + ";Persist Security Info=Fals"
        cn.Open
      End If
      Exit Function
    err_line:
     MsgBox "数据库访问错误!" + Err.Description, vbCritical, "Error"
    End Function
      

  10.   

    连接数据库之后,就可以执行查询了
     txtSQL = "select   *  from   user_Info   where   user_ID=  '" & Text1.Text & "' "Set mrc =cn.Execute (txtSQL )
    If mrc.EOF = True Then
    .....
      

  11.   

    这个问题以前有人问过,相似的代码,相似的问题;
    把ExecuteSQL那个函数贴出来看看吧,估计是那里有问题
      

  12.   

    Private   Sub   Command1_Click() 
    on error goto Err '测试错误
    '用来存放SQL语句 
            Dim   txtSQL   As   String 
    '用来存放记录集对象 
            Dim   mrc   As   New   ADODB.Recordset 
    '用来存放返回信息 
            Dim   MsgText   As   String 
            UserName   =   " " 
    '判断输入用户名是否为空 
            If   Trim(Text1.Text   =   " ")   Then 
                    MsgBox   "没有这个用户,请重新输入用户名! ",   vbOKOnly   +   vbExclamation,   "警告 " 
                    Text1.SetFocus 
            Else 
                    '查询指定用户名记录 
                    txtSQL   =   "select   *   from   user_Info   where   user_ID= ' "   &   Text1.Text   &   " ' " 
                    '执行查询语句 
                    Set   mrc   =   ExecuteSQL(txtSQL,   MsgText) 
                    'mrc.Open 
                    'If   mrc.EOF   =   True   Then 
                    If   mrc.RecordCount =   0   Then '改用这个试试看                          MsgBox   "没有这个用户,请重新输入用户名! ",   vbOKOnly   +   vbExclamation,   "警告 " 
                              Text1.SetFocus 
                              mrc.Close 
                    Else 
                            '判断输入密码是否正确 
                            If   Trim(mrc.Fields(1))   =   Trim(Text2.Text)   Then 
                            Me.Hide 
                                    OK   =   True 
                                    mrc.Close 
                                    
                                    UserName   =   Trim(Text1.Text) 
                                    frmMain.Show 
                            Else 
                                    MsgBox   "输入密码不正确,请重新输入! ",   vbOKOnly   +   vbExclamation,   "警告 " 
                                    Text2.SetFocus 
                                    Text2.Text   =   " " 
                                    mrc.Close                         End   If 
                    End   If 
            End   If 
            '记载输入密码次数 
            miCount   =   miCount   +   1 
            If   miCount   =   3   Then
           exit sub
    Err:
         msgbox Err.Description 
    end sub