[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
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...
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.
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.
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.
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...
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....
Re: Runtime error 91: object variable or with block variable not set
Originally Posted by WoF
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
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.