Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Receiving Permission denied error when attempting to append txt file

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
0
0
US

Receiving the following error:

Permission denied

Line (3617): "Set qfile = fso_OpenTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files\qtptest2.x12", ForAppending,True)".

Code:

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso=createobject("Scripting.FileSystemObject")
Set qfile1 = fso_OpenTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files\qtptest2.x12", ForAppending,True)
qfile1.WriteLine("last line of text.")


What could be causing this and how can I get access?

I was able to create the file using the following code that is in the same script


Set fso=createobject("Scripting.FileSystemObject")
'Create a non existing file "qtptest.txt " with overwrite option as True
'Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\qtptest1.txt",true,False) ' textname could become a variable so that many could be generated
'Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\ X",true,False)
'Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\ &(DataTable.Value("TxtFileName",dtGlobalSheet)",true,False)
Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files\" & TextFileName,true,False) 'TextFileName used as a variable so that multiple 834 files can be generated from DataTable
qfile1.Write((DataTable.Value("Interchange_Control_Header",dtGlobalSheet)))
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))

qfile1.Write((DataTable.Value("ISA01_I01_Author_Info_Qualifier",dtGlobalSheet)))







 
Can't be sure since I can't see all your code, but I'm going to guess that qfile1 is still open from the "Set qfile1=fso.CreateTextFile(...)" line, causing permission denied when you try "Set qfile1 = fso_OpenTextFile(...)"

If this is the case, there is no need to use OpenTextFile, since the file is already open. Alternately, you could add "qfile1.Close" before the OpenTextFile line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top