How do I integrate the VB6 CommonDialog control so that the user can enter their own file name and override a pre-determined file name?

Posted on 2011-05-08
Last Modified: 2012-05-11
I have a couple of VB6 subs that use a button click and fso to .Writeline some settings to a .txt type of file that can then use .Readline to restore the values.

Question: How do I integrate the CommonDialog control into this so that the user can enter their own file name and override the pre-determined file name? I just can't seem to get this to work...many thanks.

Private Sub mnu_SaveStatus_Click()
     SaveSettings App.Path & "\settings.set"
End Sub

Private Sub SaveSettings(ByVal FileName As String)

Set strm = fso.CreateTextFile(FileName, True)
     With strm

     .WriteLine Text1.Text
     .WriteLine Text2.Text
     .WriteLine Text3.Text

     End With

End Sub
Question by:jazjef
    LVL 76

    Accepted Solution

    You just use the control's FileName property.
    Private Sub Command1_Click()
        SaveSettings Me.CommonDialog1.FileName
    End Sub

    Open in new window

    LVL 3

    Expert Comment

    Same like GrahamSkan said.
    Place CommonDialogControl on your form and just call it on your Private Sub mnu_SaveStatus_Click()

     Like below:

    Private Sub mnu_SaveStatus_Click()
        SaveSettings CommonDialogName.FileName
    End Sub

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now