Subject: RE: Object Variable not set
I should have done more rearranging of the code.
One technique that might be helpful to you is to write ‘psuedo-code’, or a plain English representation of what you are trying to do. After you have written this, you then go back and fill in the code.
What is below is what it might look like when all is said and done (and for testing, put the code in the hotspot button if not there yet. If successful, then you should move the code to a script library and call the subroutine):
Sub Click(Source As Button)
'GET A HANDLE ON THE NOTES SESSION
Dim s As New NotesSession
'GET A HANDLE ON THE CURRENT NOTESUIWORKSPACE
Dim ws As New NotesUIWorkspace
'GET A HANDLE ON THE UIDOC AND UNDERLYING
'DOCUMENT
Dim uidoc As NotesUIdocument
Set uidoc=ws.CurrentDocument
Dim sourceDoc As NotesDocument
Set sourcedoc=uidoc.document
'GET A HANDLE ON THE CURRENT DATABASE
Dim targetDb As NotesDatabase
Set targetDb = s.CurrentDatabase
'IF THE ITEM/FIELD EXISTS IN THE DOCUMENT
If sourceDoc.HasItem(“lpkNon”) then
'GET A HANDLE ON THE FIELD TO BE PROCESSED AS A
'VARIANT
Dim vPeople As Variant
vPeople=sourceDoc.GetItemValue(“lpkNon”)
'DECLARE THE DOCUMENT THAT WILL BE CREATED
Dim targetDoc As NotesDocument
'DECLARE THE NOTESDATETIME OBJECT TO BE SET
Dim dateTime As NotesDateTime
'LOOP THROUGH THE VALUES (p) OF THE FIELD AND
'CREATE A DOCUMENT FOR EACH VALUE
Forall p In vPeople
'CREATE THE TARGET DOCUMENT
Set targetDoc = targetDb.CreateDocument
'IF THE TARGET DOC EXISTS, SET THE FIELD
'VALUES
If not (targetDoc is nothing) then
targetDoc.Form = "Acknowledgment"
targetDoc.empName = p
Set dateTime = New NotesDateTime
(Format$(Now,"Long Date"))
Call targetDoc.ReplaceItemValue("Date",
dateTime)
'SAVE THE TARGET DOCUMENT
Call targetDoc.Save( False, False )
end if
End Forall
End Sub
This method forces you to think through the code before you actually write it, reducing the likelihood of error.
You will also note that, for the most part, I pair up all my “Dim” and “Set” statements. (The exception being when something is being set inside a loop) I do not see that done much in code, but it is a method taught to be by one of the best LorusScript instructors around and really helps when trying to find errors in code.
Now if you are dealing with Names type fields here, you may have to do some more manipulation.