Solved

Creating Output Text File with Unique Name

Posted on 2002-04-05
3
142 Views
Last Modified: 2010-05-02
Hello,

I need very simple explanations. I am experimenting with VB and can get easily confused.

I am creating a simple app that creates a text file for me. I am trying to figure out how to get my app to create a filename via my input rather than hard coding the filename. I tried to use the following but it just prints everything between the quotes. Do you have a suggestion on how to do this? As you will see, the OPEN command is erroneous. I would like to put the value in a text box and then have that be the filename.

Private Sub Command1_Click()
    Dim IntFile As Integer
    IntFile = FreeFile
    Open "C:\Batch\Dat\(Text1.Text).DAT" For Append As #IntFile
        Print #IntFile, "ConvertType=" & CStr(Combo1.Text)
        Print #IntFile, "ConvertFrom=" & CStr(Combo2.Text)
        Print #IntFile, "ConvertTo=" & CStr(Combo3.Text)
        Print #IntFile, "FromDatabase=" & CStr(Text2.Text)
        Print #IntFile, "FromUserID=" & CStr(Text3.Text)
        Print #IntFile, "FromPassword=" & CStr(Text4.Text)
        Print #IntFile, "FromChecked=" & CStr(Text5.Text)
        Print #IntFile, "ToDatabase=" & CStr(Text6.Text)
        Print #IntFile, "SearchValue=" & CStr(Text7.Text)
        Print #IntFile, "Convert=" & CStr(Combo4.Text)
        Print #IntFile, "Start"
    Close #IntFile
End Sub

Eventually, I want to add browsing capability that will ask for the source file. The FromDatabase would be the default property for the ToDatabase and for the Text filename. For instance, if my FromDatabase filename is ABC.NSF the Output filename would be ABC.PST and the text file would be named ABC.DAT.

Thank you in advance,

John
0
Comment
Question by:jhieb
3 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 55 total points
ID: 6921912
YOu need to remove the reference to Text1.Text from within the quotes, e.g.:

Open "C:\Batch\Dat\(Text1.Text).DAT" For Append As #IntFile

Becomes

Open "C:\Batch\Dat\" & Text1.Text & ".DAT" For Append As #IntFile
0
 
LVL 1

Author Comment

by:jhieb
ID: 6921916
I was just getting ready to add a PS. Also, if the file exists how to I tell it to overwrite it?
0
 
LVL 20

Expert Comment

by:hes
ID: 6921928
as bhess said
Open "C:\Batch\Dat\" & Text1.Text & ".DAT" For Append As #IntFile
to overrite change to
Open "C:\Batch\Dat\" & Text1.Text & ".DAT" For Output As #IntFile
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

920 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

18 Experts available now in Live!

Get 1:1 Help Now