Illegal Function Call when trying to insure a unique file name

Morning All,

I have the following code in which I am trying to:

  1. Determine if a file already exists on a directory

  2. If it does create a unique file name for an attachment that I will detach. Note there could be more then one attachment within the named rtf.

When I run the code I am getting an Illegal Function Call error on the: fileExists = Dir$( filePath & uniqueName, 0) line of code.

Here’s the code. Any help would be greatly appreciated.

Dim splitName As Variant

Dim fileExists As String

Dim fileNum As Integer

Dim uniqueName As String

Dim filePath As String



Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim Num As Variant

Dim dis As Variant

Dim num1 As Variant

Dim rtitem As Variant

Dim view As NotesView



Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments

Set doc = collection.GetFirstDocument()

Set view = db.GetView( "Working Parts File" )

Set rtitem = doc.GetFirstItem( "DataSheet" )



If ( rtitem.Type = RICHTEXT ) Then

	Num = doc.Num

	dis = doc.DisplayAppDate

	num1 = doc.Num_2

	Forall o In rtitem.EmbeddedObjects 

		nam = ( o.Name ) 

	End Forall

	

End If



fileNum = 0

uniqueName = ("C:\Test\" & Num1(0) & "\" & Num(0) & "_"& dis(0) & "\" & nam )	

filePath = ("C:\Test\" & Num1(0) & "\" & Num(0) & "_"& dis(0) & "\" & "*.*" )

CheckName:

fileExists = Dir$( filePath & uniqueName, 0)

If Len(fileExists) = 0 Then

	Goto ExitFunction

Else

	fileNum = fileNum + 1

	splitName = Split(uniqueName, ".", 2)

	uniqueName = splitName(0) + " (" + Cstr(fileNum) + ")." + splitName(1)

	Goto CheckName

End If

ExitFunction:

				'GetUniqueFileName = uniqueName 



Messagebox uniqueName

TIA,

Teri

Subject: RE: Illegal Function Call when trying to insure a unique file name

Test your inputs. What string are you passing it? From looking at the previous three lines, I would say it’s not a correctly formatted filepath.

Subject: RE: Illegal Function Call when trying to insure a unique file name

Andre Thanks for getting back to me.

I have used those file paths on a make directory and detach file agent so they should be good unless I need something different for this.

What I did after I posted was to split out the code like below:

uniqueName = ("C:\Test" & Num1(0) & "" & Num(0) & “_”& dis(0) & "" & nam )

filePath = ("C:\Test\" & Num1(0) & "\" & Num(0) & "_"& dis(0) & "\" & "*.*" )



fileNum = 0

Messagebox fileNum

CheckName:

'fileExists = Dir$( filePath & uniqueName, 0)     'illegal function call

fileExistsDir = Dir$( filePath , 0) 

fileExistsLN = Dir$( uniqueName, 0)   

'If Len(fileExists) = 0 Then

If fileExistsDir <> FileExistsLN Then

	Goto ExitFunction

	

Else

	fileNum = fileNum + 1

	splitName = Split(uniqueName, ".", 2)

	uniqueName = splitName(0) + " (" + Cstr(fileNum) + ")." + splitName(1)

	'Goto CheckName

	

End If

This is working without throwing errors.

The new error that I am getting though is for the fileNum.

If I use my original code of fileNum = 0 then the code just keeps adding (1) to the file name such as:

first one: C:\Test\123\123_A\file (1).pdf

second: C:\Test\123\123_A\file (1) (1).pdf

Which tells me I need to get a handle on the 1 in the parenthesis and add one to that number instead of just declaring it as 0.

Am I on the right track? Or is there a better way to do this?

I will be checking out the Right function, but would like to hear back in case there is a better way or if I am forgetting something.

Thanks

Teri