CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2001
    Location
    South Africa
    Posts
    1

    Select File Dialog

    What I have: A text field [tf_location] and a button [but_browse]
    What I need to do: When the user clicks the browse button, have the standard windows Select File Dialog pop up. When the user selects a file, the dialog closes and the path of that file is displayed in the text field.
    The Problem: I am a java programmer and have no idea how to do this in VB. I am working in an MS Access environment.

    Any answers would be greatly appreciated


  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Select File Dialog

    Add the reference to the microsoft commondialog control to your project (Project, Components, etc.)

    Place the CommonDialog control on your form along with a textbox and commandbutton and this code should work for you...


    private Sub Command1_Click()

    CommonDialog1.CancelError = true
    on error GoTo Error_Handler

    CommonDialog1.ShowOpen
    Text1.Text = CommonDialog1.FileName

    Exit Sub
    Error_Handler:
    'user hit Cancel Button....
    End Sub





  3. #3
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Select File Dialog

    The previous post is right, I just want to add more. Let's assume you want to open a picture file:

    private Sub Command1_Click()
    on error GoTo Error_Handler
    With CommonDialog1

    ' Set filters.
    .Filter = "Picture Files (*.bmp;*.gif;*.ico;*.jpg;*.tif;*.tiff)|*.bmp;*.gif;*.ico;*.jpg;*.tif;*.tiff|All Files (*.*)|*.*"
    ' Specify default filter. (*.bmp)
    .FilterIndex = 1

    .CancelError = True
    .DialogTitle = "Open A Picture"

    .InitDir = strPath
    .FileName = strFileName

    ' Display the Open dialog box.
    .ShowOpen

    End With

    Text1.Text = CommonDialog1.FileName
    exit sub

    Error_Handler:
    If Err.Number = cdlCancel Then
    ' User pressed Cancel button. Do nothing
    else
    msgbox err.description
    end if
    end Sub

    Regards,

    Michi

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