Invalid or non-existent doc error when copying using LS?

I am developing a group meetings calendar using the information found from this tech article:

http://www-10.lotus.com/ldd/today.nsf/62f62847467a8f78052568a80055b380/643ef8419b72f66f85256485005505bc?OpenDocument

I have modified the appointment form in my mail database by adding a check box “TMGdbFlag”, this is to indicate if the meeting should be copied to the group calendar database.

In the QueryClose event of the form I have added the following code:

Sub Queryclose(Source As Notesuidocument, Continue As Variant)

If (source.InPreviewPane) Then Exit Sub



Dim IQMSdb As New NotesDatabase( "macnotes01" , "tmgdev\tmg_iqms_dev2.nsf" )

Dim curdoc As NotesDocument



Set curdoc = source.Document

If ( curdoc.GetItemValue("TMGdbFlag")(0) = "1" ) Then

	Call curdoc.CopyToDatabase( IQMSdb )

End If



Call csEventObj.QueryClose( Continue)

End Sub

When the “Call curdoc.CopyToDatabase( IQMSdb )” is reached I get the error "Invalid or non-existent document(mail\maildbname.nsf)

“maildbname.nsf” being the name of my mail database.

Any ideas what is causing this?