CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 1999
    Posts
    2

    Use common dialog to open a database

    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.




  2. #2
    Join Date
    Nov 1999
    Posts
    1

    Re: Use common dialog to open a database

    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
    [email protected]


  3. #3
    Join Date
    Nov 1999
    Posts
    2

    Re: Use common dialog to open a database

    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


  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Use common dialog to open a database

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured