Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seek() Error 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
How can I get the "Table has no index order set" error using the Seek() function in VFP6 using the code below? I have never had a problem using this function before. Am I missing something very basic here? If I manually set the order in the data environment of the form, I do not get the error. This code is in the destroy method of my form class and also works fine in other forms. I have also validated the database and re-indexed the table.

Code:
If Seek(gUserIDCurrent + .FunctionId, "UserRecords", "UserIdFunc")
... Other Code
Endif

Auguy
Sylvania, Ohio
 
Just a shot in the dark - try to use a variable instead of thisform reference. The error does seem odd. Are you sure this is the line of code generating an error? Are you running some timer's code also?
 
Changed to a variable instead of the thisform reference, no change. The debugger pops up and indicates this is the line with the problem. What's really strange is that if I click the continue button in the debugger, the code executes like nothing is wrong and performs exactly as intended. No timer's are involved. Do you think it has anything to do with this code being in the Destoy method?

Auguy
Sylvania, Ohio
 
Hard to say, but it may be. Are you using form's property or some other object property? If the later, the object may be already destroyed.
 
Do you have any relationhship set for this table.

By doing a search on another forum I found this reply for a slightly different situation:

1) There is a table buffered cursor opened for a table used in the from clause.
2) That cursor has "dirty" record (the record is modified, but not yet saved into buffer).
3) SQL engine creates temporary index for the table to optimize join. Check SYS(3054) output.

To workaround the problem, make sure the dirty record is saved before SQL command is executed or create the index so that SQL engine doesn't need to create temporary index on the fly.


Not sure if it applies here.
 
Here is the entire Destroy Method. I reference form properties, but no other objects. The purpose of this code is to save the current userID (gUserIDCurrent), System Function (FunctionId), and unique ID (Refnumb) and return the user to this record the next time they start this form. The property .LastRecordDisplay is just a flag indicating whether this procedure is enabled or not.

Code:
With Thisform
	* If last record display enabled, save UserId, Function ID, & Refnumb
	If .LastRecordDisplay
		Local cFunctionId, MasterFile, MasterFieldName

		* Function ID
		cFunctionId = Padr(Alltrim(.FunctionId), Len(UserRecords.FuncID))
		* Select Master File
		MasterFile = .DataEnvironment.InitialSelectedAlias

		If Not Empty(MasterFile)
			Select (Masterfile)
			* If table not empty, Save UserId, Function ID, & Refnumb of masterfile
			If Not Eof() and Not Bof()
				* Build Field Name (Use Refnumb field if none is specified in form)
				MasterFieldName = MasterFile + "." + Iif(Empty(.LastRecordFieldName), "RefNumb", Alltrim(.LastRecordFieldName))
				* Is there a record for this user & function ID combination
				If Seek(gUserIDCurrent + cFunctionId, "UserRecords", "UserIdFunc")
					* Update Refnumb value (no buffering on this table)
					If Rlock("UserRecords")
						Replace UserRecords.RefNumb With Eval(MasterFieldName) In UserRecords
						Unlock In UserRecords
					Endif
				Else
					* Create record
					Insert Into UserRecords (Usrid, FuncId, RefNumb) ;
						Values(gUserIDCurrent, cFunctionId, Eval(MasterFieldName))
				Endif
				Select (Masterfile)
			Endif
		Endif
	Endif

	* Form Cascade Method
	.FormCascadeMethod('DESTROY')
Endwith

Dodefault()

Auguy
Sylvania, Ohio
 
No relationships and no buffering. Maybe I will try buffering the table.

Auguy
Sylvania, Ohio
 
Your problem, and now I am guessing, is the
"MasterFile = .DataEnvironment.InitialSelectedAlias"
I think, the initialselectedalias is proberbly not bringing along the Index (Order)
Set the tag order before the seek and see what happens.
 
Try replacing SEEK() with INDEXSEEK()

If you still have the same problem, your index is shot.



David W. Grewe (Dave)
 
I Deleted and rebuilt the index with no success. Changed Seek() to IndexSeek() seems to have fixed problem. Thank you David! Still would like to know why seek() only fails for certain forms, but it appears to be working. Will give it a more rigorous test to see if it really does solve the problem.

Auguy
Sylvania, Ohio
 
I took a closer look at your code and I can see a situation where the "Table has no index order set" will occur intermittently.

From your code sample above the lines
....
If Not Empty(MasterFile)
Select (Masterfile)
....
If elsewhere in your form you:
1. Select the masterfile and do a set order to
or
2. Use Masterfile and never set and order

but in other places you use Masterfile
and place an order

When you hit the Seek above you may/may not will get the error.

To use the SEEK() again, someplace between the SELECT & SEEK() place the line in red. The seek will never give you that error again

If Not Empty(MasterFile)
Select (Masterfile)
Set order to ....
* If table not empty, Save UserId, Function ID,
& Refnumb of masterfile
If Not Eof() and Not Bof()
* Build Field Name (Use Refnumb field if none is specified in form)
MasterFieldName = MasterFile + "." + Iif(Empty(.LastRecordFieldName), "RefNumb", Alltrim(.LastRecordFieldName))
* Is there a record for this user & function ID combination
If Seek(gUserIDCurrent + cFunctionId, "UserRecords", "UserIdFunc")





David W. Grewe (Dave)
 
Thanks again David, I will try that also. Maybe I should have been more clear, but the Seek() is on the UserRecords table, not the (MasterFile) which is different on each form. I have no index set on the UserRecords table in the data environment. If I do set the index in the data environment, that fixes the problem, but why should I have to do that? Anyway IndexSeek() is working, but I will try your latest solution just to see if it works as well.

Auguy
Sylvania, Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top