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.
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.