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!

Data Environments 2

Status
Not open for further replies.

bluesw3

Programmer
May 27, 2003
11
0
0
US
Is there anyway to modify the Data Environment of a form during runtime?
 
HI

instead of depending on Data ebvironment, you can use code to open and close files. That will be easier.

Example..

USE myTable ALIAS myTable IN 0

so you can ignore data environment.

If you have opened a table in Data environment and want to close it..
USE IN myTable where myTable was opened in dataenvironment.

:)

:)

ramani :)
(Subramanian.G)
 
Another option, similar ramani but not using an alias is to open the table referenced as a variable. This usually works fine by itself, but sometimes you must reference both table and field so us a double period.

I'll explain:

Code Outside of Form
lcTable = "customer' && could be any table of choice
DO myFORM with lcTable

Code Inside of Form
INIT EVENT
lParm tcTableIn
THISFORM.tableIn = tcTableIn

* Now you have the name stored as a property on the form so any method can use it and the variable does not have to be public.


* Example of a method
LOCAL lcTable
lcTable = THISFORM.tableIn
IF NOT USED(lcTable)
USE (lcTable)
ELSE
SELECT (lcTable)
ENDIF

To reference it by table field:

messagebox(&lcTable..City)


This method may appear confusing, and it may be a bit more work, but the nice part is that it opens the table with its actual name and you do not need an alias name. Using an alias can cause problems later if someone else (multi-user) is trying to use the same table. The, IF USED('customer'), for example, will return False if you try to open it and it's opened as an alias. As a result the use statement fails.

Example of code causing error.
USE customer alias boo
IF NOT USED('customer')
USE customer IN 0
ENDIF

In summary, it is more work saving the table to a variable or property and then referencing it, but it avoids an error when someone else is trying to access it.

In saying that, there will be those who say just use the AGAIN clause on the use statement, but that can get very sloppy and lead to multiple copies of the table open often referenced as "A", "B", etc.

Now you don't have to worry about the data environment. You don't have to worry about the multi-user issue as a result of the ALIAS statement.

I know this is confusing, but hopefully some of it make sense. It would probably be a good FAQ if written correctly.

Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top