I'm new to this forum, so greetings!
Anyways, the problem I have right now is a 'runtime 70 error' (permission error).
Yes, I do have full access to the file and folder where the text file is located - which is why I'm asking, why does the following code prompt me with a permission error?
*** Reading from the file works. Writing does not (Output does not work).
This is the first sub, which basically checks to see weather the text file exists or not. If it does, it reads the info from it. If not, it creates a text file, then it prompts the user with a form to input the info.
The next portion of code is located in the form. This is where I get the error when trying to write to the text file.Public Sub userInfo() Dim fn As Integer Dim oFSO, sFileName Set oFSO = CreateObject("Scripting.FileSystemObject") fn = FreeFile sFileName = "H:\gstLetterInfo.txt" If oFSO.FileExists(sFileName) Then GoTo readFile Else Set objfso = CreateObject("Scripting.FileSystemObject") Set objFile = objfso.CreateTextFile(sFileName) MsgBox "This is your first time using this macro. Please enter your contact information.", vbInformation, "First Time Use" frmInfo.Label_User.Caption = userID frmInfo.Show End If Exit Sub readFile: Open sFileName For Input As #fn '' Didn't even get to this point yet Line Input #fn, userName Line Input #fn, userPhone1 Line Input #fn, userPhone2 Line Input #fn, userPrinter MsgBox userName & userPhone1 & userPhone2 & userPrinter ''''' Close #fn End Sub
Kind of a long question, hopefully it has a short answer!Private Sub Button_Submit_Click() Dim fn As Integer sFileName = "H:\gstLetterInfo.txt" fn = FreeFile '' ''<CODE>'' '' userName = Text_Name.Value userPhone1 = Text_Phone1.Value userPhone2 = Text_Phone2.Value userPrinter = Text_Printer.Value Open sFileName For Output As #fn Print #fn, userName Print #fn, userPhone1 Print #fn, userPhone2 Print #fn, userPrinter Close #fn Unload Me End Sub
Thanks for your help,
- Shane
Last edited by Shane O; 06-01-2010 at 10:45 AM.
I solved my own problem...
It worked by taking out:
Set objfso = CreateObject("Scripting.FileSystemObject") Set objFile = objfso.CreateTextFile(sFileName)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks