I’m getting “Object Variable Not Set” for line temp4=doc2.GetItemValue(“doc2.Fatalities_1(0)”)
Sub Initialize
Dim workspace As NotesUIWorkspace
Set workspace=New NotesUIWorkspace
Dim uidoc As notesuidocument
Set uidoc=workspace.currentdocument
Dim doc As NotesDocument
Set doc=uidoc.Document
Dim temp1 As String, temp2 As String, temp3 As Integer, temp4 As Integer, janfatalitytotal As Integer
'here are the keys to search view below
temp1=doc.CurrentYear(0)
temp2=doc.PlantLocation(0)
temp3=doc.death(0)
Dim Session As NotesSession
Set Session = New NotesSession
Dim db As NotesDatabase
Set db=Session.CurrentDatabase
Dim view As NotesView
Dim keys(1 To 2) As String
Set view = db.GetView("All 2004 - By Plant")
keys(1)=temp1
keys(2)=temp2
Dim doc2 As NotesDocument
Set doc2 =view.GetDocumentByKey(keys)
'temp4=doc2.Fatalities_1(0)
temp4=doc2.GetItemValue("doc2.Fatalities_1(0)")
janfatalitytotal=temp4+temp3
Call doc2.ReplaceItemValue("Fatalities_1(0)",janfatalitytotal)
Call doc2.Save(False,True)
End Sub
-------- Here is what I’m trying to do -----------------
When saving “doc”, post save calls up the above.
Based on 2 fields on doc 1, I’m looking to a certain view. The view will contain only 1 document. I want to take the value of doc.field and doc2.field and add them together, then replace the value of the field on doc2.
From what I can tell in the debugger, everything is working until I get to the temp4 line.
Your doc2 is not set (Empty when you debug). That’s why you are getting that error. Make sure your keys are right. It’s the problem with your keys. Hence not returning any document.
Tom pointed out the problem. I overlooked this. As Tom said, do not use doc2.Facilities_1(0) inside the brackets. Inside brackets when you use GetItemValue should be only “Facilities_1” with double quotes, instead of doc2.Facilities_1(0)
It keeps stopping on the temp4 line saying object variable not set.
I took off the (0) as suggested, also took it off in the replaceitemvalue line. The view I’m looking to has first column Ascending and Categorized, the second column is Ascending only.
If you specify a single key, the key can correspond to a value in a sorted column that is either categorized or not categorized. If you specify multiple keys, each key must correspond to a value in a sorted column that is also categorized.
See my or Tom’s posting above. You cannot get the error if you put “Finalists” instead of doc.Finalists2(0). If you still get it, make sure those two columns are sorted and identify the problem in your both ‘keys’.
Key1 and Key2 show up correctly in the debugger. I took off that (o). Doc 2 doesn’t have a + sign in debugger. It just shows Doc 2 and nothing drops down under it.
Here is the updated code:
Sub Initialize
Dim workspace As NotesUIWorkspace
Set workspace=New NotesUIWorkspace
Dim uidoc As notesuidocument
Set uidoc=workspace.currentdocument
Dim doc As NotesDocument
Set doc=uidoc.Document
Dim temp1 As String, temp2 As String, temp3 As Integer, temp4 As Integer, janfatalitytotal As Integer
'here are the keys to search view below
temp1=doc.CurrentYear(0)
temp2=doc.PlantLocation(0)
temp3=doc.death(0)
Dim Session As NotesSession
Set Session = New NotesSession
Dim db As NotesDatabase
Set db=Session.CurrentDatabase
Dim view As NotesView
Dim keys(1 To 2) As String
Set view = db.GetView("All 2004 - By Plant")
keys(1)=temp1
keys(2)=temp2
Dim doc2 As NotesDocument
Set doc2=view.GetDocumentByKey(keys)
'temp4=doc2.Fatalities_1(0)
temp4=doc2.GetItemValue("Fatalities_1")
janfatalitytotal=temp4+temp3
Call doc2.ReplaceItemValue("Fatalities_1",janfatalitytotal)
Call doc2.Save(False,True)
It must be a problem with your keys. Check that the columns in your view are both text
If so try to narrow it down by only searching for the first key. If this works then you know it is the second key that is the problem.
If not switch the order of the columns in the view so that the 2nd key is the first column and then try searching for the 2nd key only to see if that works.
You should then be able to narrow down the cause of the problem.
Your doc2 seems not getting set. That’s why you still get error. It is not setting up because of your keys. Though you get values in keys, they might not be matching with the column values in the view. Hence your doc2 is not at all setting. Change the lookup keys as below(in code and also in view column):
This should definitely set your the doc2. And you can replace Fatalities in doc2 by adding the existing value with the value of ‘death’ field from doc, without any problem.
Now in the view:
In First column —>Concatenate the fields of your first column and second column so that they will be like @Text(CurrentYear) + “-”+@Text(PlantLocation)
Delete your second column so that it will not exist.
However, I have to edit the doc2 manually and save or select it and choose refresh selected docs in order for the view to update.
I do have “Refresh fields on Keyword change” on my form too.
The field on doc2 is a computed number field. That field adds up the field that was changed by the LS. On doc2 there is a fatalities field for each month.
I’ve tried a few things but can’t get goc2 to refresh to appear in the view correctly.