为什么会出现"对象变量或With块变量未设置"?
是出现在"If RS.RecordCount <> 0 Then"这一行
谢谢帮助~
------------------------------------------------
Option Explicit
Dim dbs As Database
Dim RS As Recordset
Dim FindName As String
Dim strID As String
Public LoginSucceeded As BooleanPrivate Sub cmdCancel_Click()
    '设置全局变量为 false
    '不提示失败的登录
    LoginSucceeded = False
    Me.Hide
End SubPrivate Sub cmdOK_Click()
    '检查正确的密码
    strID = txtUserName
    FindName = "ID='" & (strID) & "' "
    If RS.RecordCount <> 0 Then
        RS.MoveFirst
    End If
    RS.FindFirst FindName
    If RS.NoMatch Then
        '将代码放在这里传递
        '成功到 calling 函数
        '设置全局变量时最容易的
        MsgBox "无效的ID,请重试!", , "登录"
        txtUserName.SetFocus
        SendKeys "{Home}+{End}"
    Else
        If txtPassword = RS.Fields("pw") Then
            If txtUserName = "admin" Then
                strState = True
            End If
            LoginSucceeded = True
            Me.Hide
            frmStart.Hide
            frmMain.Show
        Else
            MsgBox "密码错误,请重试!", , "登录"
            txtPassword.SetFocus
            SendKeys "{Home}+{End}"
        End If
    End If
End Sub
Private Sub Form_Load()
  Dim cn As New ADODB.Connection
Dim RS As New ADODB.Recordsetcn.CursorLocation = adUseClient
cn.Open "Provider=SQLOLEDB.1;Password=test;Persist Security Info=False;User ID=test;Initial Catalog=manage;Data Source=192.168.1.102"
RS.Open "select * from qx", cn, adOpenKeyset, adLockReadOnlyEnd Sub
Private Sub Form_Unload(Cancel As Integer)
   PwdWS.Close
End Sub

解决方案 »

  1.   

    你有没有引用ADO对象库???你首先要在VB菜单中:
    “工程”-->“引用”-->“Microsoft AxtiveX Data Objects 2.X Library”
    注:2.X为版本号,如果你机子上有高版本的就用高版本的,如:2.5或2.6的。
      

  2.   

    set RS = new Recordset
    If RS.RecordCount <> 0 Then
      

  3.   

    ADO我已经引用~
    加入set RS = new Recordset
    运行后说"无效使用NEW 关键字"
      

  4.   

    Dim RS As ADODB.Recordset
        Set RS = New ADODB.Recordset
      

  5.   

    OK..谢谢..
    顺便再问一下..RS.NoMatch里没有NOMATCH方法吗?有什么可以替代的方法吗?