Prevent to input same title in DB (LotusScript)

I want to create LotusScript to prevent user to key in same title (PC Asset Tag) that already have in DB. Example: in DB already have PC Asset Tag IT12345, then user want to key in the same PC Asset Tag IT12345. what I want to do is if user key in the same number, the massage box appear to tell the user that already have that number and cannot be save.

Below is my code:


Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim PCAssetTag As String

Dim view as NotesView

Dim col as NotesViewEntryCollection



Set uidoc = workspace.CurrentDocument



AssetTag = uidoc.FieldGetText("PCAssetTag")



'this code if textfield empty will appear the message

If ( uidoc.FieldGetText( "PCAssetTag" ) = "" ) Then

	Messagebox "You must enter the PC Asset Tag number",,"Warning"

	Call uidoc.GotoField( "PCAssetTag" )

	continue = False

End If



'this code to validate the length in textfield when user input more then 10 character

If ( Len(AssetTag) > 10 ) Then

	Messagebox "Maximum 10 characters only for PC Asset Tag number",,"Warning" 

	Call uidoc.GotoField( "PCAssetTag" )

	continue = False 

End If

I have a problem in below coding


'this code to validate text field if user key in the same number that already have in DB.

Set view = thisdb.GetView("LookupView")

Set doc = view.GetDocumentByKey(AssetTag)

If Not (doc Is Nothing) Then

	MsgBox "There is already hace PC Asset Tag number " & AssetTag & "."

	Continue = False

End If

End Sub


my form Name: MainForm

my view name: LookupView

textfield name: PCAssetTag

when I want try to save my form, the error massage appear “Variant does not contain an object”.

Anyone can help me, I’m beginner in LotusScript.

Subject: Prevent to input same title in DB (LotusScript)

Your concept is valid. YOu say ‘I have a problem in below coding’. Describe the problem. What do you see in the debugger and how is the code behaving?

Subject: Prevent to input same title in DB (LotusScript)

Doug’s right about the debugger. You would also have saved yourself if you had used Option Declare (don’t consider that an optional addition to your code; not only does it pick up undeclared variables, it also picks up a lot of typos that wind up producing undeclared variables).

There’s a second problem that you are going to encounter once you get the code working: your document cannot be edited and re-saved. You’re quitting the save if you find a document with the same asset tag. What if the document you find is the document you’re working on? You’ll need to check that (comparing the UNID of the found document to the UNID of the current document is probably safest; if they’re the same document, allow the save).