在作mis系统的时候,遇到一个问题。Private Sub Command1_Click()
Dim txtSql As String
Dim txtMsg As String
Dim mrc As ADODB.RecordsettxtSql = "select * from user where username='" & txtName.Text & "'"
Set mrc = ExcuteSql(txtSql, txtMsg)
If mrc.EOF = False Then      /*发生错误的语句*/
    If mrc.Fields(1) = Trim(txtPassword.Text) Then
        frmMDI.Show
        Unload Me
    Else
        MsgBox "密码不正确,重新输入!", vbOKCancel + vbExclamation, "警告!"
        Exit Sub
    End If
Else
    MsgBox "无此用户"
End IfEnd Sub以上是运行的代码,错误提示:
实时错误'91':
对象变量或with块变量未设置请问怎么解决这个问题?

解决方案 »

  1.   

    Dim mrc As ADODB.Recordset改成Dim mrc As new ADODB.Recordset
      

  2.   

    或者加一句
    set mrc=new adodb.recordset
      

  3.   

    set mrc=new adodb.recordset
    加在什么地方?
      

  4.   

    加入这个set mrc=new adodb.recordset
    又出现第一个错误了!
      

  5.   

    Dim mrc As new ADODB.Recordset
    dim cnn as new adodb.connection
    dim textsql as string
    cnn.connectionstring="provider=..............."  '連接字串
    cnn.open 
    txtSql = "select * from user where username='" & txtName.Text & "'"
    mrc.open textsql,cnn,adOpenStatic, adLockPessimistic
      

  6.   

    dim cn as new adodb.connectionset cn =new  adodb.connection
    strcon="provider=..............."  
    cn.open strcon
    txtSql = "select * from user where username='" & txtName.Text & "'"
    cn.excute txtsql