Click to See Complete Forum and Search --> : Use common dialog to open a database


Simon Paul
November 20th, 1999, 07:47 PM
I'm hoping someone can help me with a newbie problem here...

I want to use a common dialog to allow a user to open a database. How do I get the database name and path from the common dialog and then open the database for use by some simple forms.

Thanks in advance.

ANoakes
November 21st, 1999, 06:13 PM
The answer to your question is as follows:
--
Dim strFilePath As String
Dim strDatabase As String

CommonDialog1.ShowOpen

strFilePath = CommonDialog1.FileName
strDatabase = CommonDialog1.FileTitle
--
CommonDialog1.FileName will return the full path of the database.
CommonDialog1.FileTitle will return just the name of the database.

Good question.

Allen Noakes
VB Programmer/Analyst
Dames & Moore Group
misan@dames.com

Simon Paul
November 29th, 1999, 05:07 PM
Allen,

Thanks for the reply.

I understand your suggestion and I will use that. What I am doing is using a standard module to load some forms and control the common dialog to select the database. Some of the forms (MDIchild forms) have the controls on them to access the database. Is there a need (or a smart way) to open the database for processing so that the strDatabase and strFilePath variables can simply be passed to the controls to allow their processing.

Without dumping the whole project so far on here, this is slightly complex. I guess a application or code sample would help me. Any suggestions?

Thanks once again for your help.

Simon

Chris Eastwood
November 29th, 1999, 05:20 PM
You could have the path/database name in a global variable (declared in a bas module), or a better (OO) method would be to have a single instance of a class which stores the database details. You could then update the class on the fly and notifies the forms accordingly (with events)

Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb