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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

close table after select query into cursor but keep cursor active

Status
Not open for further replies.

ioniq

Programmer
Jun 12, 2023
3
RO
Hi, can someone help me to solve the following problem:
I have this code:
1.SELECT field1,field2 FROM table INTO CURSOR crs
2.use in (select("table"))

3.use table in 0 alias tblalias
4.sele tblalias
5.brow

I get "File is in use" al line 3.
I need to let cursor active but i need to close table
Please help me to solve this.
 
try
Code:
Use in select('table')



If you want to get the best response to a question, please check out FAQ184-2483 first.
 
If you really use the name “table” you may get some problems as this is a reserved word in Foxpro. Use a “normal” name for your table, like “sales”, “invoices”, “stock” or whatever you need.

Regards, Gerrit
 
If your select is optimizable with a filter, VFP will do that. That can be the case if you have a where clause that's fully optimizable but also, if you have no where clause at all.

Check out what a filter cursor is in the help. Also, you can detect that with DBF("crs") being the DBF itself, not just a TMP file as a normal cursor is. You can force a cursor to be no filter with a NOFILTER clause. And if you also want to be able to replace values in the cursor use the READWRITE clause.


So
Code:
SELECT field11, field2 FROM table INTO CUROSR crs NOFILTER && or READWRITE
USE IN SELECT("table")

By the way, if you detect you have a filter cursor, you can actually also access fields of the dbf you didn't query, that's another way of detecting you deal with a filter cursor.
Code:
Open Database _samples+"Northwind\Northwind.dbc"
Select CustomerId From northwind!customers Into Cursor crs
? Dbf("crs") && it's not a TMP file it is the customers.dbf
? crs.address && though address wasn't queried and a BROWSE does only show the CustomerId column, you can access other fields.
It's a trick of VFP to suggest it's faster than it could possibly be and in cases like yours it has indirect effects like the "File is in use" error you don't expect after explicitly closing the DBF. It also does affect the possibility to query FROM crs and the error you then get is that 'CRS' must be created with SELECT ... INTO TABLE. That would work, true, but also NOFILTER or READWRITE make crs a workarea that differs from the DBF and can be queried, so it is misleading.

Chriss
 
Thank you Chris Miller ! It worked perfectly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top