I'm writing a code to export the CSV using free file in lotus notes the code works fine but I'm facing an issue while closing the file explorer window. The scenario is if I don't need to export now and unknownly click export button it asks for fine name opening the file explorer window. The file explorer window it is not closing it asks for filename and its looping till i give the file name.
My code:
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim source As NotesUIDocument
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim headerString As String
Dim header As Variant
Dim sno As Variant
Dim vw As NotesView
Dim flag As Boolean
REM Get selected document
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set dc=db.Alldocuments
Set doc = dc.GetFirstDocument
sno=0
Dim count As Variant
count=0
While Not doc Is Nothing
filenames = ws.SaveFileDialog( _
False,"File name",, "E:\samp", ".csv")
If Not(IsEmpty(filenames)) Then
REM Write Body item to file
fileNum% = FreeFile()
Open filenames(0) For Output As fileNum%
headerString ="S.No,UNID,NAME,STATUS,TIME"
header = Split(UCase(headerString),",")
Print #fileNum%, headerString
Do Until doc Is Nothing
If (CStr(doc.Getitemvalue("Status")(0)="Accepted")) Then
sno=sno+1
d=sno+","+doc.Universalid+","+doc.Getitemvalue("Uname")(0)+","+doc.getitemvalue("Status")(0)+","+doc.Getitemvalue("Time")(0)
Print #fileNum%,d
flag=0
Else
flag=1
End If
Set doc = dc.Getnextdocument(doc)
count=count+1
Loop
Else
End If
Wend
If (flag="1") Then
MsgBox"no documents were accepted"
Else
MsgBox "Document exported successfully"
End If
Close fileNum%
End Sub
If Not(IsEmpty(filenames)) Then
'<code removed for brevity>
Else
set doc = nothing
End If
Put an else statement in as above, this way when you send no file name, the doc is set to nothing and the while loop exits.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments