Results 1 to 11 of 11

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

  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,170

    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,170

    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,170

    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,170

    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!

  10. #10
    New Member
    Join Date
    Aug 2020
    Posts
    1

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

    Hello Seenu
    I have similar kind of problem i am accessing the web scraping through VBA, please could look into it. thanks in advance

    Sub Login()

    Dim i As SHDocVw.InternetExplorerMedium


    Set i = New InternetExplorerMedium

    i.Visible = True
    i.navigate "https://tgct.gov.in/tgvatisreports/"

    Do While i.readyState <> READYSTATE_COMPLETE
    Loop

    Dim idoc As MSHTML.HTMLDocument
    Set idoc = i.document

    'MsgBox idoc
    idoc.getElementsByTagName("Input").Item("OffUidtxt").Value = "hello"




    End Sub

  11. #11
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,905

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

    You replied to a thread which is 8 years old.
    The thread is about ADO, queries and recordsets, while your question is about webscraping.
    Next you say you are using VBA, which has it's own subforum.

    And we don't like webscraping requests
    What do you want to scrape from a login page on taxes page?

Posting Permissions

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



Click Here to Expand Forum to Full Width