CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Join Date
    Jun 2010
    Posts
    18

    [RESOLVED] Runtime error 91: object variable or with block variable not set

    please i need help once again. what seems to be the problem with this? it generated an error saying "object variable or with block variable not set". this is the simplified code:

    Code:
    Private Sub Form_Load()
    
        Me.KeyPreview = True
        Call DbfOpen
        Call DispData
    
    End Sub
    
    Private Sub DbfOpen()
    
        Data1.DatabaseName = (App.Path)
        Data1.RecordSource = "cust.dbf"
    
    End Sub
    
    Private Sub DispData()
    
        Label1.Caption = Data1.Recordset.Fields("ACCOUNT") 'the error points to this line
    
    End Sub

  2. #2
    Join Date
    Apr 2009
    Posts
    394

    Re: Runtime error 91: object variable or with block variable not set

    Do you actually have VFP (Visual Fox Pro) or dBase? I ask because you really need to have a look at the field names contained within the cust.dbf and I'll tell you why. Why is because most of the time *.dbf files will not contain a full name like account for a field name. Don't ask me why, it may be because the designer is lazy, but usually I have seen field names like ACC when it comes to *.dbf files... which means, I believe you have the wrong field name...



    Good Luck

  3. #3
    Join Date
    Jun 2010
    Posts
    18

    Re: Runtime error 91: object variable or with block variable not set

    i don't think that i have an error with the field names. if i did the program this way the program runs fine just by ommiting the "Call DispData" on Form_Load(). please check the functional code below.

    Code:
    Private Sub Form_Load()
    
        Me.KeyPreview = True
        Call DbfOpen
        'Call DispData - disable the dispdata
    
    End Sub
    
    Private Sub DbfOpen()
    
        custDbfData.DatabaseName = (App.Path)
        custDbfData.RecordSource = "cust.dbf"
    
    End Sub
    
    Private Sub DispData()
    
        Label1.Caption = custDbfData.Recordset.Fields("ACCOUNT") 
    
    End Sub
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        
        If KeyCode = vbKeyEscape Then 'Escape Key is pressed
            frm_inqquit.Show
        End If
        
        If KeyCode = vbKeyPageDown Then 'Pagedown key is pressed
            
            custDbfData.Recordset.MoveNext
            If custDbfData.Recordset.EOF = True Then
                custDbfData.Recordset.MoveLast
            End If
            Call DispData
    
        End If
        
        If KeyCode = vbKeyPageUp Then 'Pageup key is pressed
            
            custDbfData.Recordset.MovePrevious
            If custDbfData.Recordset.BOF = True Then
                custDbfData.Recordset.MoveFirst
            End If
            Call DispData
            
        End If
        
        If KeyCode = vbKeyEnd Then 'End Key is pressed
            custDbfData.Recordset.MoveLast
            Call DispData
        End If
        
        If KeyCode = vbKeyHome Then 'Home key is pressed
            custDbfData.Recordset.MoveFirst
            Call DispData
        End If
            
    End Sub
    the code above has no error. all i want to happen is to call for disdata on form_load, but it generates error.
    Last edited by torpydoo; July 10th, 2010 at 09:17 AM.

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

    Re: Runtime error 91: object variable or with block variable not set

    Have you tried running your simplified code?
    It looks ok considering your other code works.
    The only thing I can think of would be that the code has not yet completed the creation of the recordset when the dispdata is called but that should not happen either.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Jun 2010
    Posts
    18

    Re: Runtime error 91: object variable or with block variable not set

    the simplified code has error. the only thing that changes between them is the "call dispdata" in the form_load, when it is in there, error occurs, when it's not there, there's no error. notice also, that the "call dbfopen" is called prior to dispdata, so the recordset creation is complete. in fact the entire program is good and running, the only bothering me is i wish i could initialise the data being displayed by calling the dispdata in the form_load section, but i couldn't.

  6. #6
    Join Date
    Jun 2010
    Posts
    18

    Re: Runtime error 91: object variable or with block variable not set

    maybe i cannot use "Call DispData" on Form_load.

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Runtime error 91: object variable or with block variable not set

    Use Form.Activate() instead
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Jun 2010
    Posts
    18

    Re: Runtime error 91: object variable or with block variable not set

    use where?

  9. #9
    Join Date
    Jun 2010
    Posts
    18

    Re: Runtime error 91: object variable or with block variable not set

    i made a simple program of the error.. how do i attach files here for the gurus to evaluate?

  10. #10
    Join Date
    Jun 2010
    Posts
    18

    Re: Runtime error 91: object variable or with block variable not set

    please see attached file. the simplified source code of my program.
    Attached Files Attached Files

  11. #11
    Join Date
    Jun 2010
    Posts
    18

    Re: Runtime error 91: object variable or with block variable not set

    up..

  12. #12
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Runtime error 91: object variable or with block variable not set

    What comes to my mind:
    App.Path is NOT a DataBaseName. The database appears to be Cust.dbf, I'd say
    RecordSource is supposed to be a table within that database.
    I'M not sure what dBaseIV has got there, but either the Recordset is Nothing, or the Field is Nothing.
    Unfortunately I have no foxpro on this machine here so I cannot look into the dbf file...

  13. #13
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Runtime error 91: object variable or with block variable not set

    Quote Originally Posted by WoF View Post
    Unfortunately I have no foxpro on this machine here so I cannot look into the dbf file...
    I could open the file in Excel and at least it actually has a data field named ACCOUNT. Didn't know for now what else to look for...
    Last edited by Eri523; July 10th, 2010 at 08:40 PM.

  14. #14
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Runtime error 91: object variable or with block variable not set

    torpydoo, please attach files in .zip format, instead of .rar - as most members will most likely have winzip installed instead of winrar. Also, please do not bump threads like what you did in post #11. Good things come to those who wait....

    Hannes

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

    Re: Runtime error 91: object variable or with block variable not set

    Quote Originally Posted by WoF View Post
    What comes to my mind:
    App.Path is NOT a DataBaseName. The database appears to be Cust.dbf, I'd say
    RecordSource is supposed to be a table within that database.
    I'M not sure what dBaseIV has got there, but either the Recordset is Nothing, or the Field is Nothing.
    Unfortunately I have no foxpro on this machine here so I cannot look into the dbf file...
    In the case of dbf the database is the folder name and the tables are the dbf files contained therein
    Always use [code][/code] tags when posting code.

Page 1 of 2 12 LastLast

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