Receiving invalid key value type error message in LotusScript

1143015 pts.
Lotus Notes
In LotusScript, I keep getting this strange "invalid key value type" error when I'm trying to search a view using the UserName as the key. Would this be due to the LotusName type? How can I get around this? Here's my code:
 Sub aiv_checkPersonIsValid
Checks that the person(s) that have been entered into the location database are valid
members of the CCL Address Book

Function calls: N/A
Sub calls: N/A
Called in event: onChange (to populate fields)
Called in action: Save and Close, Save, Save And Add Another
Called by: co_countValuesAndPopulate() 

Public Function aiv_checkPersonIsValid (userName As NotesName) As Boolean

Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim peopleDb As NotesDatabase
Dim peopleView As NotesView
Dim peopleDoc As NotesDocument
Dim thisDoc As NotesDocument
Dim uidoc As NotesUIDocument
Dim key(0) As Variant
Dim noMatchFound As String
Let noMatchFound = "No match found for this name. Please choose a name from the      menu provided."
Dim PersonNameField As NotesItem        
'Dim userName As NotesDocument
Set uidoc = w.CurrentDocument
Set thisDoc = uidoc.Document        

    'get handle to People database and check we've found the database
    Set peopleDb=s.GetDatabase("****", "ccldevelopmentLocSysPeople.nsf")
    If Not peopleDb Is Nothing Then

            'get handle to view in People database and check we've found the view
            Set peopleView = peopleDb.GetView("AllLocSysLookup")
            If Not peopleView Is Nothing Then

                'Make the PersonNameField variable equal to the value of the first item in the Person Name Field
                Set PersonNameField = thisDoc.GetFirstItem("PersonName")

        ForAll pName In PersonNameField.Values
            'Start to loop through the PersonNameField and check that the names chosen exist in the people database 
            'lookup record in People database which matches the name in the PersonName field on this document   

            Set userName = New NotesName(pName)

            Set key(0) = userName

            'Set peopleDoc = peopleView.GetDocumentByKey(uidoc.Document.GetItemValue("PersonName")(0), True)
            Set peopleDoc = peopleView.GetDocumentByKey(key, True)

                    'If there is no match found to the document in the peopleDb, show a MsgBox
                    If peopleDoc Is Nothing Then
                                MsgBox "No match found in the CCL People Database for '" + pName.Common + "'. Please choose a valid name.", 0, "Error: No match found"
                    Exit Function
                    End If

        'End Loop   
        End ForAll

    End If
End If

End Function

Answer Wiki

Thanks. We'll let you know when a new response is added.

In general, I would suggest turning on the debugger and using it to step through your code line by line.  That will show you variable values and help you find the offending line and variable(s).

In this particular case, I think you’ll find that pname is a text string and that there is no point in creating the username NotesName object (are you trying to change the parameter that was passed to the function?).  So, you could set key(0) to pname.  In fact, you could probably just use pname in the getdocumentbykey call.  The other thing to watch for is that the PersonName field is not blank due to the doc not being saved or reloaded/refreshed.

Discuss This Question:  

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: