[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...
Good Luck
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.
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
maybe i cannot use "Call DispData" on Form_load.
Re: Runtime error 91: object variable or with block variable not set
Use Form.Activate() instead
Re: Runtime error 91: object variable or with block variable not set
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?
1 Attachment(s)
Re: Runtime error 91: object variable or with block variable not set
please see attached file. the simplified source code of my program.
Re: Runtime error 91: object variable or with block variable not set
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
Quote:
Originally Posted by
WoF
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... :ehh:
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
Re: Runtime error 91: object variable or with block variable not set
Quote:
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
1 Attachment(s)
Re: Runtime error 91: object variable or with block variable not set
thanks for the inputs.. i don't think that there is an error with the recordsource and databasename. when the call dispdata on the form_load is disabled, the program works fine without altering the contents of DbfOpen().
please see the attached zip file below. and my apologies for posting "up" on post #11.
Re: Runtime error 91: object variable or with block variable not set
Okay, I'm going to show you something that I think will solve your problems... BUT first let me tell you what I did to your project before I show you this code...
You want to know what I did? NOTHING... :) You already have the reference to get this code to work and it is called, just so you know, DAO ODBC DIRECT!!! (BTW, your reference to DAO 3.51 is what you needed for this...)
Code:
Option Explicit
'declare variables needed to access the records in the *.dbf file...
Dim daoWs00 As DAO.Workspace
Dim daoDb00 As DAO.Database
Dim daoRs00 As DAO.Recordset
Private Sub Form_Load()
'create a DAO ODBC Direct workspace object
Set daoWs00 = DBEngine.CreateWorkspace("Test", "", "", dbUseODBC)
'use workspace object to set database object = to workspace objects opendatabase method
'NOTE: the ODBC DSN "Visual FoxPro Tables" should already be on your system but double check to make sure
Set daoDb00 = daoWs00.OpenDatabase("Visual FoxPro Tables", dbDriverComplete, False, _
"ODBC;DSN=Visual FoxPro Tables;UID=;PWD=;SourceDB=" & App.Path & ";SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;")
'okay, select everything from the source table...
Set daoRs00 = daoDb00.OpenRecordset("SELECT * FROM cust1.dbf", dbOpenDynamic)
'and just to prove a point, display a value...
MsgBox daoRs00.Fields("FRANCHISE")
Me.KeyPreview = True
Call DbfOpen 'to open the required databases
'Call DispData 'this bothers me
End Sub
Good Luck
Re: Runtime error 91: object variable or with block variable not set
thanks a lot sir, for your effort. that was too complicated for me to understand lol. believe me, im a total noob with a little background in programming, but somehow i was able to create my desired system little by little.
i just edited this post to reply:
i did integrated your code to my existing work, it did work!!! (standing ovation for you) now, i won't be using those "data control"'s and hide them somewhere. i just learned a new trick in using and opening a dbase IV file. but now i have a new question; can i open several dbase IV files using your sample codes?? assuming to use your code, how can i create index file just like what usually did in foxpro (MS DOS version)(like "INDEX ON ACCOUNT TO ACT")? do i have to create a new post thread for this???
Re: Runtime error 91: object variable or with block variable not set
What I showed you is a Free Table Directory access which is different than a database directory but you should still be able to add indexes via standard sql alter table statements. If not, try the database driver, see the odbc manager under control panel for its name...
Good Luck
Re: Runtime error 91: object variable or with block variable not set
thanks sir. the issue is resolved.