Code to create code

GregSmith

Registered User.
Local time
Today, 16:55
Joined
Feb 22, 2002
Messages
126
I have a command button that when pressed should create a text file with some code in it.

I am in need of some code that will show me how to write a txt file and create some text.
 
Code:
Sub fWriteSomeText(sFileName As String)
    Open sFileName For Output As #1
        Write #1, "bleh some text"
    Close #1
End Sub

As well you can substitute variables to print out as well

Code:
Sub fWriteSomeText(sFileName As String)
dim sCodeListing as String
sCodeListing = "bleh some code"
    Open sFileName For Output As #1
        Write #1, sCodeListing
    Close #1
End Sub


-nate
 
This is what I am using so far...

When it hits the [Site] it displays the ID number instead of the name. Any ideas why?

Private Sub Command387_Click()
On Error GoTo Err_Command387_Click

Dim stAppName As String
Dim stUser As String
Dim stFullName As String

stFullName = LCase([FirstName] & "." & [LastName])
stUser = LCase(Left([LastName], 6) & Left([FirstName], 1) & ([MiddleI]))
Open "add-nt.txt" For Output As #1
Print #1, "[Users]"
Print #1, stUser + "," + stFullName + "," + stUser + "," + [Site] + ",U:,\\SHQSR10A\Users\usert,,kix32 usernfo.kix"
'usert,User Test,usert123,testing,U:,\\SHQSR10A\Users\usert,,kix32 usernfo.kix
Close #1

stAppName = "notepad add-nt.txt"
Call Shell(stAppName, 1)

Exit_Command387_Click:
Exit Sub

Err_Command387_Click:
MsgBox Err.Description
Resume Exit_Command387_Click

End Sub
 
Sorry Greg i do not know why it would show a number instead of the location like you want.

On a side note if you are adding information to this text file rather than creating a new one over and over you will want to open it up "For Append" rather "For Output". "For Output" will overwrite it everytime thus losing any additions made before.

Just so you are not trying to add records into an existing txt file only to have all old entries deleted.
 
This does it:

stSiteName = Me.Site.Column(1)

It now works!!
 

Users who are viewing this thread

Back
Top Bottom