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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In which database does a form reside?

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I have a library database that contains a bunch of forms. All my databases set a reference to this library database. I have a ribbon that launches forms from the current database and from the library database. When a form is opened a ribbon is assigned to the form. On the ribbon is an image that indicates in which environment the form resides (i.e. Live Database, Test database, etc.).

Therefore, I need to know the database the current form resides. That is, does the form that is being opened resided in the library database or the current database?

Is their a property or method or something that indicates the owner of the form?
 
What you are saying does not make sense to me...

I have a ribbon that launches forms from the current database and from the library database.

Do you mean that you are controlling the connection to multiple backends and using one fronted?
 
I kind of solved the problem by just checking the prefix of the form name. That will tell me whether the form resides in the CurrentProject or CodeProject. For example, all of my forms in my library db begin with "frmHMS_". But I would prefer a more secure way of checking because some other programmer, at some point in time, may add a form whose name does not follow the convention.

I'll try to explain what I'm doing and why I'm doing it.

I have about a dozen databases I've created and about 200 users. So, to ensure that I don't inadvertantly modify the wrong data, I have 2 icons on the ribbon that indicate in which envrionment the form I'm currently accessing resides (i.e. Live, Test, Dev) and in which environment the table (RecordSource of the form) resides.

For the FE db, I have a table that specifies the folder the Live FE db resides and the folder the Test FE db resides, etc. Consequently, when the form opens I can compare CurrentProject.path with the values in the table to determine in which environment the form (ie the FE database) resides.

In the FE db I simply link all of my tables to the BE db that represents the Live environment and then run some code that stores the connection string of each table along with the name of the FE database. I then link all of my tables to the BE db that represent the Test environment and run the code that stores the connection string of each table. I do the same for Dev and Archive. So when I open a form I can check to see in which environment the Recordsource of the form is referencing by comparing connection strings. (This also gives me the ability to switch environments on the fly. For example, switching to the Archive BE database.)

My problem is that the form that I open could reside in my Library database (which may represent Live, Dev, Test) or the Current database. If the form is in the current database, I can check CurrentProject.path to determine the environment the FE db resides. Else I would check CodeProject.path. My original question was, is there a property or something that indicates the name and path of the database the form in question resides? For example, does Form1 reside in MyCurrentDb.accdb or does it reside in MyLibraryDb.accdb?

A thought: I could search MSysObject in both databases for the form in question. Assuming that I don't have same form name in both databases. I have no control over this since multiple programmers are developing databases using my library.
 
What isn't clear is what you are doing with library forms... Do you open them with some sort of automation and you need to know based on the object where you opened it? If so the Form's Parent should be the forms collection and it's parent is the database object and it's name property is the path and file of that database. I'm kind of assuming there is a parent property all the way up the chain... Or you could see if the form exists in various database files programmatically, basically if you reference a form and it is not there, it will error, trap the error and return false in that case.
 

On the ribbon I have listed all of the lookup forms. And also lookup forms that exist in the library database. For example, the library database may contain a Dept. form. Via the onButton action I call a library routine to open the form selected.

I've tried checking the parent property (via debug) but at the time I need to check in which environment the form is running, the parent property is not available. It states "The expression you entered has an invalid reference to the Parent property".

I think I will just have to go with the naming convention and if other programmers do not follow the convention, that's their problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top