mrc对象还没有建立,所以不允许这样操作!

解决方案 »

  1.   

    Set mrc = ExecuteSQL(txtSQL, MsgText)
    在前面有这个呀
      

  2.   

    有没有定义过阿
    dim mrc as recordset
      

  3.   

    我已经定义了
    Dim mrc As ADODB.Recordset
      

  4.   

    Option Explicit
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
    Public OK As Boolean
    '记录确定次数
    Dim miCount As Integer
    Private Sub Form_Load()
        Dim sBuffer As String
        Dim lSize As Long
        sBuffer = Space$(255)
        lSize = Len(sBuffer)
        Call GetUserName(sBuffer, lSize)
        If lSize > 0 Then
            txtUsername.Text = ""
       
        Else
            txtUsername.Text = vbNullString
        End If
            OK = False
        miCount = 0
    End SubPrivate Sub cmdCancel_Click()
        OK = False
        Me.Hide
    End Sub
    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这就是那段代码,主要是要完成登陆判断的
      

  5.   

    在Set mrc = ExecuteSQL(txtSQL, MsgText)之前要先定义
    Set mrc=New ADODB.Recordset