Switching between databases in the data environment 
Author Message
 Switching between databases in the data environment

I am new to vfp. I use vfp 6 and win 2000.

I would like the user to be able to switch between different data
bases sitting in different folders. Each database has the same
structure, but one database has data for this year, one for last year,
etc.

My forms use data environment and I have tried to use

thisform.SetAll("Database", oapp.appcdatfolpat , "Cursor")

where oapp.appcdatfolpat is the path to the current database, to
switch between the folders.

Here is an example:

On a form I have a data environment called DATAENVIRONMENT with a view
called VEVENTS. I have set the data environments AutoOpenTables
to false.

On the form I have a grid with recordsource VEVENTS and
RecordSourceType 1 Alias.

In the forms load method I have this code:

thisform.SetAll("Database", oapp.appcdatfolpat , "Cursor")
thisform.dataenvironment.opentables()

where oapp.appcdatfolpat gives the path to the current data base, e.g.
c:\sportsday\2003\it.dbc.

This is the problem:

thisform.dataenvironment.opentables() does not look for the database
in oapp.appcdatfolpat, but, it seems, in the home() folder.

What am I doing wrong?

Please remember I am using vfp 6, not 8.

Any help is greatly appreciated.

Sincerely,

Jan Nordgreen



Thu, 01 Sep 2005 22:03:51 GMT  
 Switching between databases in the data environment
Jan,

All you should ever need to do is to SET DATABASE in the main program, once
that's done all of the views and tables opened will come from that DBC in
whatever folder it's located in.

--
df - Microsoft MVP FoxPro http://www.geocities.com/df_foxpro


Quote:
> I am new to vfp. I use vfp 6 and win 2000.

> I would like the user to be able to switch between different data
> bases sitting in different folders. Each database has the same
> structure, but one database has data for this year, one for last year,
> etc.

> My forms use data environment and I have tried to use

> thisform.SetAll("Database", oapp.appcdatfolpat , "Cursor")

> where oapp.appcdatfolpat is the path to the current database, to
> switch between the folders.

> Here is an example:

> On a form I have a data environment called DATAENVIRONMENT with a view
> called VEVENTS. I have set the data environment’s AutoOpenTables
> to false.

> On the form I have a grid with recordsource VEVENTS and
> RecordSourceType 1 – Alias.

> In the form’s load method I have this code:

> thisform.SetAll("Database", oapp.appcdatfolpat , "Cursor")
> thisform.dataenvironment.opentables()

> where oapp.appcdatfolpat gives the path to the current data base, e.g.
> ‘c:\sportsday\2003\it.dbc’.

> This is the problem:

> thisform.dataenvironment.opentables() does not look for the database
> in oapp.appcdatfolpat, but, it seems, in the home() folder.

> What am I doing wrong?

> Please remember I am using vfp 6, not 8.

> Any help is greatly appreciated.

> Sincerely,

> Jan Nordgreen



Fri, 02 Sep 2005 02:29:23 GMT  
 Switching between databases in the data environment
Jan forget the setall nonsense, put this in your form class's load event. If
you want to use it in the dataenvironment's BEFOREOPENTABLES Change the
THIS.DATAENVIRONMENT to THIS every where the word This.Dataenvironment
appears in the code below

This is a double loop, the first opens and sets the database, the second
sets your tables. Create a public variable first "mdbfpath" , store the path
to the folder in it, Allow the user to change the folder etc then store the
value in the variable.

Pay close attention to the " ****** "

IF THIS.DATAENVIRONMENT.OBJECTS.COUNT > 0
 LOCAL oObj AS DATAENVIRONMENT,nBufferMode AS NUMBER,;
  cDatabasePath AS CHARACTER,cPath AS CHARACTER
 WITH THIS.DATAENVIRONMENT
  .CLOSETABLES
    ****** open and set the databases
  FOR i = 1 TO .OBJECTS.COUNT
   DO CASE
    CASE ALLTRIM(UPPER(.OBJECTS(i).BASECLASS)) = "RELATION"
     LOOP
    CASE EMPTY(.OBJECTS(i).DATABASE)
     LOOP
    OTHERWISE
     oObj = EVALUATE("THISFORM.DATAENVIRONMENT.OBJECTS(i)")

    ********* as we store our databases in multiple folders, the
dataenvironment refrences them as
    ********* "C:\ITS\DATABASES\ITS_SYSTEM\ITS_SHARED.DBC" thats why the
RAT() is
    ********* pointing to the 2 occurance of "\".  IF all your databases are
in a single folder, check the dataenvironment
    ******** for the position of the last "\" and put the appropriate
occurance below. Do the same in the second loop

     cDatabasePath = SUBSTR(oObj.DATABASE,RAT("\",oObj.DATABASE,2)+1)
    ****************************************************            ^^
*********
    cPath = mdbfpath+cDatabasePath
     OPEN DATABASE (cPath)
     SET DATABASE TO (cPath)
   ENDCASE
  ENDFOR
*******set the path for the tables
 FOR x = 1 TO .OBJECTS.COUNT
   DO CASE
    CASE ALLTRIM(UPPER(.OBJECTS(x).BASECLASS)) = "RELATION"
     LOOP
    CASE EMPTY(.OBJECTS(x).DATABASE)
     LOOP
    OTHERWISE
     oObj = EVALUATE("THISFORM.DATAENVIRONMENT.OBJECTS(x)")
     nBufferMode = oObj.BUFFERMODEOVERRIDE
    **************************************
     cDatabasePath = SUBSTR(oObj.DATABASE,RAT("\",oObj.DATABASE,2)+1)
****************************************************                 ^^
*********
     cPath = mdbfpath+cDatabasePath
     oObj.DATABASE = cPath
     oObj.BUFFERMODEOVERRIDE = nBufferMode
   ENDCASE
  ENDFOR
  .OPENTABLES
 ENDWITH
ENDIF

Good Luck
Mohammed


Quote:
> I am new to vfp. I use vfp 6 and win 2000.

> I would like the user to be able to switch between different data
> bases sitting in different folders. Each database has the same
> structure, but one database has data for this year, one for last year,
> etc.

> My forms use data environment and I have tried to use

> thisform.SetAll("Database", oapp.appcdatfolpat , "Cursor")

> where oapp.appcdatfolpat is the path to the current database, to
> switch between the folders.

> Here is an example:

> On a form I have a data environment called DATAENVIRONMENT with a view
> called VEVENTS. I have set the data environment’s AutoOpenTables
> to false.

> On the form I have a grid with recordsource VEVENTS and
> RecordSourceType 1 – Alias.

> In the form’s load method I have this code:

> thisform.SetAll("Database", oapp.appcdatfolpat , "Cursor")
> thisform.dataenvironment.opentables()

> where oapp.appcdatfolpat gives the path to the current data base, e.g.
> ‘c:\sportsday\2003\it.dbc’.

> This is the problem:

> thisform.dataenvironment.opentables() does not look for the database
> in oapp.appcdatfolpat, but, it seems, in the home() folder.

> What am I doing wrong?

> Please remember I am using vfp 6, not 8.

> Any help is greatly appreciated.

> Sincerely,

> Jan Nordgreen

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.461 / Virus Database: 260 - Release Date: 3/10/2003


Fri, 02 Sep 2005 14:56:51 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. DataBase Designer and the Data Environment

2. Database Views are opened exclusive in a form's data environment

3. Data Environment and DataBases

4. ENVIRONMENT SWITCHES-FPD26

5. VFP 5.0 Form,Data Environment, Data Session

6. Data Environment and Data Source

7. Data Environment/Data Session

8. Switching Connections/Database during Run-time

9. Switching Databases

10. Switching from local to remote data

11. How to display which users are using which databases in a multiuser environment inside VFP

12. Foxpro Databases in a Unix environment

 

 
Powered by phpBB® Forum Software