dcsimg
Results 1 to 9 of 9
  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Resolved [RESOLVED] Run-time error 91 Object variable or With block variable not set

    hi,please help with error message code Run-time error 91 Object variable or With block variable not set

    Code:
    With cboempNo
            .clear
    Set rs1 = OpenRecordset("select distinct EmployeeNo From Employee,WHERE Status = 'Active'", adOpenStatic, adLockReadOnly)
       While Not rs1.EOF error message highlight at this line 
                cboempNo.AddItem rs1!EmployeeNo & vbNullString
                rs1.MoveNext
            Wend
            rs1.Close
    Set rs1 = Nothing
    End With

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,165

    Re: Run-time error 91 Object variable or With block variable not set

    is this line ok? it shuld be DB.OpenRecordset isnt it?
    Code:
    Set rs1 = OpenRecordset("select distinct EmployeeNo From Employee,WHERE Status = 'Active'", adOpenStatic, adLockReadOnly)
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: Run-time error 91 Object variable or With block variable not set

    seenu_1st:
    yes,is DB.OpenRecordset.The problem still the same.

  4. #4
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,165

    Re: Run-time error 91 Object variable or With block variable not set

    can u try this
    Code:
    set rs1 = DB.OpenRecordset("select distinct EmployeeNo From Employee WHERE Status='Active'")
    if still problem, pls attach the project as zip if posible.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: Run-time error 91 Object variable or With block variable not set

    seenu_1st:
    another error appear Runtime error "424" object required!

  6. #6
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,165

    Re: Run-time error 91 Object variable or With block variable not set

    can u post the declaration, connection code? there may be any missing
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: Run-time error 91 Object variable or With block variable not set

    Code:
    Private Sub Form_Load()
    Dim rs1 As ADODB.Recordset
    Dim UserId As String
    Dim EmployeeNo1 As String
    
    
    With cboempNo
            .clear
    'Set rs1 = OpenRecordset("select distinct EmployeeNo From Employee,WHERE Status = 'Active'", adOpenStatic, adLockReadOnly)
     Set rs1 = DB.OpenRecordset("select distinct EmployeeNo From Employee WHERE Status='Active'")
       While Not rs1.EOF
                cboempNo.AddItem rs1!EmployeeNo & vbNullString
                rs1.MoveNext
            Wend
            rs1.Close
    Set rs1 = Nothing
    End With
    
    
    
    lpPrevWndProc = SetWindowLong(DataGrid1.hWnd, GWL_WNDPROC, AddressOf WndProc)
    End Sub

  8. #8
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,165

    Re: Run-time error 91 Object variable or With block variable not set

    grace, u r confusing with DAO and ADO, try this code, dont forget to set reference to MS ActiveX Data Object Library, change the path and filename of mdb file as u need in the blue color line
    Code:
    Option Explicit
    'set reference to MS Activex Data Objects Library
    
    Dim cn As ADODB.Connection  'this is the connection object
    Dim rs As ADODB.Recordset   'this is the recordset object
    
    Private Sub Form_Load()
    Set cn = New ADODB.Connection
    'specify the connectionstring
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & App.Path & "\DB1.mdb"
    'open the connection
    cn.Open
    
    'instantiate the recordset object
    Set rs = New ADODB.Recordset
    'open the recordset
    With rs
        .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        
        .Open "select distinct EmployeeNo From Employee WHERE Status='Active'"
        
        While Not rs.EOF
            Combo1.AddItem rs!EmployeeNo
            .MoveNext
        Wend
    End With
    End Sub
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: Run-time error 91 Object variable or With block variable not set

    thanks the problem solved!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.