Vbform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harshakusam
    New Member
    • Apr 2009
    • 36

    #1

    Vbform

    Hi All,

    I Created a form and now i want to add a command button and a text box
    and then when user clicks on command button browse window should open and users can select the path and seleted path should be shown in text box.

    Cheer's
    Harsha
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    Assuming you have a form with a text box and a button.

    Following code is in a module

    [code=vb]
    Public Function fPickDirDialog( txtSelectedDir As String) As String

    ' Requires reference to Microsoft Office 12.0 Object Library.

    Dim fDirDialog As Office.FileDial og

    ' Set up the File Dialog to show only directories
    Set fDirDialog = Application.Fil eDialog(msoFile DialogFolderPic ker)

    With fDirDialog

    ' Allow user to make a single selection in dialog box
    .AllowMultiSele ct = False

    ' Set the title of the dialog box.
    .Title = "Please select a directory"


    ' Show the dialog box. If the .Show method returns True, the
    ' user picked at least one dir. If the .Show method returns
    ' False, the user clicked Cancel.
    If .Show = True Then
    ' return the directory and path chosen
    fPickDirDialog = .SelectedItems( 1)
    Else
    fPickDirDialog = txtSelectedDir
    End If
    End With
    End Function
    [/code]

    Following code is in the OnClick event of your button:

    [code=vb]
    If IsNull(Me.txtYo urTextBox) Then Me.txtYourTextB ox= "C:\"
    Me.txtYourTextB ox= fPickDirDialog( Me.txtYourTextB ox)
    [/code]

    cheers,

    Originally posted by harshakusam
    Hi All,

    I Created a form and now i want to add a command button and a text box
    and then when user clicks on command button browse window should open and users can select the path and seleted path should be shown in text box.

    Cheer's
    Harsha

    Comment

    Working...