Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File SaveAs fucntion 1

Status
Not open for further replies.

MaxbyMike

Mechanical
Jun 18, 2001
17
0
0
CA
I was wondering if any one could help me?
I wrote a program that out puts CAD files. But want I need is a way for the user to select what directory they want the files to be saves in. It would be nice is I could get their choice as a string so I can add it to the rest of the needed file information.
Thanks for your Help
Mike mikepacholski@hotmail.com
 
Replies continue below

Recommended for you

You can use the SaveAs form from the Common Dialog Control. But, with this, the user would have to specify a filename. It sounds like you are looking to get the directory. If you want an example on using this control, just let me know. DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
That's what I'm looking for, some code that will allow the user to select a directory form their computer. An example of this would be great.
Thanks
Mike (mikepacholski@hotmail.com)
 
Add the Microsoft Common Dialog Control to your Project>Components. Add the Common Dialog Control to your form (Named dlg in this example). Then, under your OK button, you can insert the following:
Code:
    Dim sFileName As String
    Dim UsrRes, s1 As String
    
    dlg.Filter = "Text File (*.txt)|*.txt"
    dlg.InitDir = "C:\Temp\"
    dlg.ShowSave
    
    sFileName = dlg.FileName
    sPartName = dlg.FileTitle
    
    If Len(sFileName) = 0 Then
        MsgBox "Cancelled!"
    ElseIf Dir(sFileName) <> &quot;&quot; Then
        'File Already Exists - Prompt User
        s1 = sFileName & vbCrLf & &quot;Already Exists.&quot; & _
             vbCrLf & &quot;Should I overwrite the file?&quot;
        
        UsrRes = MsgBox(s1, vbYesNo + vbDefaultButton2, _
                &quot;Overwrite Existing File?&quot;)
        
        If UsrRes = vbNo Then
            MsgBox &quot;Orignal File Preserved!&quot;, _
                    vbOKOnly, &quot;New File Not Saved!&quot;
        Else
            Kill sFileName
        End If
    End If
    
    'Save your file
    MsgBox sFileName
Hope this helps! DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Status
Not open for further replies.
Back
Top