Use defined error - QueryOpen

I has two same databases but stored in difference path. There is a hotspot button at one of the form with the following code:

Dim session As New NotesSession

Dim db As NotesDatabase

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim curdoc As NotesDocument

Dim picklisttitle As String

Dim picklistcontent As String

Dim newdoc As NotesDocument

Dim uidoc2 As NotesUIDocument



Set uidoc = ws.CurrentDocument

Set curdoc = uidoc.Document

'Call MarkExField ("ContactUNID", "ZZ_ContactUNID")

picklistTitle = GetLabelValue("Dialog Label"+"Pay Term Attention Title"+"DGL0001")

If picklistTitle = "" Then

	picklistTitle = "Contact"

End If

picklistContent  = GetLabelValue("Dialog Label"+"Pay Term Attention Content"+"DGL0001")

If picklistContent = "" Then

	picklistContent = "Please select a contact: "

End If

Call HotspotPickValueFromView ("Use Internal", "(lkup Contact by DocumentNumber)", False, 3, "ContactUNID", "CompanyDocumentNumber", picklistTitle, picklistContent)

'If CompareTwoFieldValues (curdoc, "ZZ_ContactUNID", "ContactUNID") = False Then

Call ContactHotspotLookupValueFromView ("(Documents by UNID)", "ContactUNID")

Call ReplacePayTermContentVariable(curdoc)	

Set db = session.CurrentDatabase

Set newdoc = New NotesDocument(db)

Call curdoc.CopyAllItems(newdoc)

curdoc.ZZ_MainDocStatus = "Deleted"

curdoc.ZZ_DocStatus = "Deleted"	

Call curdoc.Save(True,False)

curdoc.SaveOptions = "0"





Set uidoc2 = ws.EditDocument(False,newdoc)

uidoc2.EditMode = True



Call uidoc2.Refresh

Call uidoc.Close		

It prompts “User defined Error” when existing at QueryOpen

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)

If Not Source.IsNewDoc Then

	If Source.Document.UniversalID <> "" Then

' Create Check In Document

		Call CreateCheckIn(Source.Document.UniversalID,"Edit")						

	End If

End If		

End Sub

However, the problem appears only in one of the database. I cannot found why the problem do not appear in another database.