CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    42

    Run Time Error:91

    Code:
    Private Sub stock()
    Set Record = New ADODB.Recordset
    Record.Open "Select * from Stockin where ProductCode='" & TxtDesc.Text & "'", Connect, 1, 3
    With Record
        If .EOF = True And .BOF = True Then
        Else
            txtQty.Text = Record!Qty
            txtpack.Text = Record!Packing
            txtPrice.Text = Record!SalesPrice
    Record.Close
    Set Record = Nothing
    End If
    End With
    End Sub
    Object variable or with block variable not set

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Run Time Error:91

    Which line gives the error?

    My guess would be that Connect is not set to anything

    As I mentioned before Connect and Record are not good choices for object names

    You should move that record.close and set record=nothing to after the end if.
    If you are going to use a with block you should actually use it but in the code above it is actually only used on one line.
    There is also no need to check both eof and bof
    Code:
    Private Sub stock()
        Set Record = New ADODB.Recordset
        With Record
            .Open "Select * from Stockin where ProductCode='" & TxtDesc.Text & "'", Connect, 1, 3
            If Not .EOF Then
                txtQty.Text = !Qty
                txtpack.Text = !Packing
                txtPrice.Text = !SalesPrice
            End If
            .Close
        End With
        Set Record = Nothing
    End Sub
    Always use [code][/code] tags when posting code.

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

Featured