>In putting together an app, I ask the user for a project number upon startup. If the project does not exist, I'd like to replicate the DBC and it's tables in a sub-directory and use that as the data for my main application.
>
>I'm wanting to do this for easy backup, organization and archiving - and to make it easier for users to manage their files.
>
>That being said, I'm having trouble figuring out how to create the data environment of my primary application. How do I tell my form to look in a certain directory for it's DBC, instead of the one I used for design? Do I need to empty the data environment and instead open the tables and create the relationships in the calling program? I know this is the way I always used to do it - perhaps I'm just getting lazy!
>
>TIA
You just need to change the database property for the objects in the dataenvironment of each form. This has to be done before the tables are opened, so do it a ,method called from form.load or Form.DataEnvironment.BeforeOpenTables. Here is the code from my ChangeDataPath method in my base form class. It is called with the path as a parameter, usually from form.load. The form gets its datapath from the application object.
LPARA tcNewDataPath
LOCAL lnCnt, loObj, lcDBC, lcNewDataPath
IF TYPE("tcNewDataPath") <> "C"
RETURN .F.
ELSE
lcNewDataPath = tcNewDataPath
ENDIF
LOCAL ARRAY laList[1]
=AMEMBERS(laList, THISFORM.DATAENVIRONMENT, 2)
IF EMPTY(laList[1])
RETURN
ENDIF
IF ALEN( laList,1 ) > 0
FOR i = 1 TO ALEN(laList,1 )
loObj = EVAL("ThisForm.DataEnvironment."+laList[i])
IF LOWER(loObj.BASECLASS ) = 'cursor' AND "\"$loObj.DATABASE
IF !EMPTY(loObj.DATABASE)
lcDBC = SUBSTR(loObj.DATABASE, RAT('\', loObj.DATABASE))
loObj.DATABASE = tcNewDataPath + lcDBC
IF !DBUSED(loObj.Database)
OPEN DATABASE (loObj.Database)
ENDIF
SET DATABASE TO (loObj.Database)
ELSE
lcDBC = SUBSTR( loObj.CursorSouce, RAT('\',loObj.CursorSouce))
loObj.CursorSouce = tcNewDataPath + lcDBC
ENDIF
ENDIF
NEXT
ENDIF
Erik Moore
Clientelligence