
Set Database Name property using no path
Quote:
> I am using a number of standard data controls to bind DBCombo boxes to
> fields and have them filled with the list of data. This all works fine
> except that I have browsed to the database with the data control for
> the DatabaseName property and again I want to get around having the
> database in the specified path.
> How can I set the DatabaseName property using no path?
I assume you want the app to work regardless of where the app/database is
installed. You can set the DatabaseName property of each data control at
runtime, once your app knows where the database is.
The bottom line is that you must either assume the database is in a path
relative to App.path and set DatabaseName from a "constructed" path built
from App.Path + some subdirectory, or you will need to have the user define
where the DB is so that the program can store and retrieve that information
at startup and then set all the data controls' DatabaseName properties at
runtime.
In one application we designed, we always place the DB in a "Data" directory
under the application's EXE directory during installation. The program
starts by assuming it's there (App.Path & "\Data\mydb.mdb"). If it's not
there, it checks for a registry entry that will contain the DB location. If
that doesn't exist, or the DB doesn't exist in the location specified in the
registry, then it prompts the user using a Browse for Folder style dialog
and saves the response in the registry for the next boot.
We also created a generic sub that is called during Form_Load to set all the
data controls on a single form:
Public Sub SetFormDBPaths(Frm As Form)
Dim I As Integer
For I = 0 To Frm.Controls.Count - 1
If TypeOf Frm.Controls(I) Is Data Then
Frm.Controls(I).DatabaseName = gDBPath + DATABASE_FILENAME
End If
Next I
End Sub
So, in every Form_Load, we have the same simple call: Call
SetFormDBPaths(Me)
This is just one way of doing it, but it should give you some ideas.
--
Vinnie Murdico
Software with Brains, Inc.
http://www.softwarewithbrains.com