?
Solved

Simple File Processing Question

Posted on 2003-03-23
4
Medium Priority
?
148 Views
Last Modified: 2010-05-01
Dear all,
I'm saving and opening Files using FSO. When the File path is 'hard coded' thus:

Set fsoStream = fso.CreateTextFile("c:\ApplicationArchive\MyApplicationSettings.STP", True)

everything works fabulously.

However, what I want to be able to do is to get the path and filename from the user via a 'Save File As' Dialog box, and use that in the fsoStream expression to create the file.

I've tried the following but it doesn't work:

Text1.Text= "c:\ApplicationArchive\MyApplicationSettings.STP" 'captured from user via Dialog box
Dim FileString as String
FileString = Chr(34) & Text1.Text & Chr(34)
Set fsoStream = fso.CreateTextFile(FileString, True)

What am I doing wrong? How can I use the returned path and filename in a variable to create the file using FSO?

Thanks
0
Comment
Question by:DoctorNash
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 100 total points
ID: 8190694
You don't need the Quotes

Text1.Text= "c:\ApplicationArchive\MyApplicationSettings.STP" 'captured from user via Dialog box
Dim FileString as String
'Leave out the quotes
FileString = text1.text
Set fsoStream = fso.CreateTextFile(FileString, True)

What am I doing wrong? How can I use the returned path and filename in a variable to create the file using FSO?
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8190709

FileString = Chr(34) & Text1.Text & ".STP" & Chr(34)
0
 
LVL 7

Expert Comment

by:vbwizardry
ID: 8190754
Here is a sample program it will give you an idea of how to do save as in you application.
You need
Form
TextBox Name=txtPath
CommandBotton Name=cmdSave
CommonDialog controll Name=dlgDialog
Include Microsoft Scripting Runtime

Option Explicit
Private Const csFilter As String = "Stp (*.stp)|*.stp"
Private oFs As FileSystemObject

Private Sub cmdSave_Click()
Const ErrorSource = "Error in Form1: Sub cmdSave_Click"
Dim oTextWriter As TextStream

    On Error GoTo cmdSave_Click_ErrHandler
    txtPath.Text = vbNullString
    dlgDialog.CancelError = True
    dlgDialog.DialogTitle = "Save As..."
    dlgDialog.Filter = csFilter
    Call dlgDialog.ShowSave
    txtPath.Text = dlgDialog.FileName
    Set oTextWriter = oFs.CreateTextFile(txtPath.Text, True)
    ' do your code here
    dlgDialog.InitDir = oFs.GetParentFolderName(txtPath.Text)

    Exit Sub
cmdSave_Click_ErrHandler:
End Sub

Private Sub Form_Load()
    dlgDialog.InitDir = App.Path
    Set oFs = New FileSystemObject
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set oFs = Nothing
End Sub
0
 

Author Comment

by:DoctorNash
ID: 8199957
PaulHews, Thanks for your accurate and to-the-point response. Full Marks to you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

800 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