Dan,
While you don't have to open the file using this technique, FoxPro does, and as Dave points out FP doesn't close it. So either you'll have to explicitly close it, or if you are in a Private data session it will be closed when it's closed.
1. A form can be set with private data session by setting the forms property..
DataSession = 2 && means private datasession. By default this is 'default data session'.
2. When you want to insert a record in a particular table and you dont want that to remain open after opening it.. appending the record ... then you can do the following in the recording procedure..
USE myTable IN 0 ALIAS myTable
INSERT INTO myTable FROM MEMVAR && or whatever
USE IN myTable && this closes the table
The above does not disturb the current alias and so you dont have to worry about the current selected table.
There are four types of classes that use a datasession:
- The session class (available since VFP 6.0)
- A form
- A form set
- A toolbar
If you want to instantiate a session without an object bound to it, use the session class.
If you have an object (Form, Formset, Toolbar) and you close it (by releasing the object), the private datasession will be closed automatically, closing your cursors (views, cursors, tables) with it.
A lot of times one of my team come and ask me a question how to ……
After some discussion even after we find a way to do it, we find out that this is not the best way to do it. My alert for this kind of situations is to try to reverse the logic behind how things work, this post is an example for this situation.
Natively, Fox will not do it for you but it is possible any ways with some pain and C code. But my advice is to review your design and see what led you to this unusual situation. I believe you will find some thing not right
I know you guys want to know. I have a system that allows different projects to be build. Each project is contained within a master table and does not get its unique table. Each task has tables created using structures that is named project+task. One of the tables gets the default information that can be later be extracted and put in the project+task table. The project manager can decide that the default info will not fully meet their needs and add to a project+task table. However, they wanted this additional information added to their default information at the project level not the project+task level.
You have convinced me to rethink this table to be at the project level and not project +task level.
It's still not clear what this situation has to do with "Adding a record to a table without opening the table." What prevents you from opening the table? If nothing, just do an "INSERT INTO ..." then close the table using "USE IN tablename". If the trouble is that a different program is using the table already, make both programs non-exclusive ("SET EXCLUSIVE OFF".
All of the code to update the record is in a procedure that has as field pointer generic Alias not the filename. I would have to duplicate the code for an insert, which is info coming from 3 tables and fields being combined. The generic alias is already in use by the working project+task.
I was looking for the easy way out. Add to inactive tables. This turns out not be a good idea. I was hoping for a low-level table code that could do that.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.