Validating an empty field then Print #fileNum% to file

Hi There,

Im trying to validate if a field not empty … then print this into the txt file, it reads and inserts the first part but doesnt insert the second part … I’ve tried and search for why its not working but im beginning to think it cant work?

Here is an example of my code:

If Not(Isempty(filenames)) Then

fileNum% = Freefile()

Open filenames(0)

For Output As fileNum%

If doc.manager(0) <> “” Then

Print #fileNum%, "This is a test "

Set doc = collection.GetNextDocument(doc)

Elseif doc.manager2(0) <> “” Then

Print #fileNum%, "This is a test 2: "

Set doc = collection.GetNextDocument(doc)

End If

Close filenum%

Subject: What does the debugger tell you?

If you mean that you never see 'This is a test 2" line then:

Run the code with the debugger on and confirm that you have records that have a value in doc.Manager(0) and then determine the value of doc.Manager2(0).

You might have a document set where every doc has a completed manager(0).

You might have a set where every doc that has on Manager(0) has a Manager2(0).

Or maybe you don’t have the right field names.

Or…something else.

The debugger is a big help working out this kind of issue.

Subject: RE: What does the debugger tell you?

Thanks for the response Doug, I’ve debugged and noticed that it does not even read the second line of code

Elseif doc.manager2(0) <> “” Then

Print #fileNum%, "This is a test 2: "

Set doc = collection.GetNextDocument(doc)

End If

When I remove the Elseif, it prints to the file.

Not sure why its not liking the Elseif?

Subject: RE: What does the debugger tell you?

If doc.manager1(0) contains a value, the else-if part will never execute. That is how else-if works.

If condition1 Then

block of code to be executed if condition1 is true

ElseIf condition2 Then

block of code to be executed if the condition1 is false and condition2 is true

Else

block of code to be executed if the condition1 is false and condition2 is false

End If

So when you run the code in the debugger, you should see the value of doc.manager1(0) and be able to see why the if-statement acts like it does.

Also, you should not use extended notation, use the GetItemValue method of the NotesDocument class instead, for performance and compatibility reasons.

Subject: RE: What does the debugger tell you?

Thank you Karl-Henry and Doug for the assistance and insight on this issue.

I have broke up my if statements and it is now working!

Great appreciated :slight_smile: