Object variable not set

I have this piece of code to pick line items from orders and it works sometimes and doesn’t at other times. I’ve seen other posts with this error but not when it concerns opening other database’s.

Any help would be appreciated.

Thanks

Tim


Sub Initialize

On Error Goto ErrorHandler

Dim s As New NotesSession

Set doc = s.documentcontext

doc_num = doc.order_number(0)

Set partsDB = New NotesDatabase("","partsdata.nsf")

If Not partsDB.IsOpen Then

	Call partsDB.Open( "", "partsdata.nsf" )

End If

Set inv_v = partsDB.GetView("invbyorder")

Set inv_items = New NotesRichTextItem(doc,"inv_items")

'SetTable

Call GetAllItems("Order")

'CloseTable

Exit Sub

ErrorHandler:

Call ErrorHandler("GetOrderItems")

End Sub

Subject: Recommendations

Use s.GetDatabase() instead of NewDim all your objects (e.g., the invbyorder)

Subject: RE: Recommendations

I’m not sure if this is what you meant?


Sub Initialize

On Error Goto ErrorHandler

Dim s As New NotesSession

Dim inv_v As NotesView

Dim inv_items As NotesRichTextItem

Dim invbyorder As NotesView





Set doc = s.documentcontext

doc_num = doc.order_number(0)



Set partsDB = s.GetDatabase("","partsdata.nsf")

Set inv_v = partsDB.GetView("invbyorder")

Set inv_items = New NotesRichTextItem(doc,"inv_items")

'SetTable



Call GetAllItems("Order")

'CloseTable

Exit Sub

ErrorHandler:

Call ErrorHandler("GetOrderItems")

End Sub

Subject: RE: Recommendations

Tim, could you please let me know if the recommendation worked or not since I’m having exactly the same problem with one of my agents.

Thanks

Subject: RE: Recommendations

Please stop writing code like this. You have no checks to see if the objects are instantiated properly. Add more error handling :

Sub Initialize

On Error Goto ErrorHandler

Dim s As New NotesSession

Set doc = s.documentcontext

if (doc is nothing) then

‘’ do something

end if

if doc_num.hasItem(“number”) then

doc_num = doc.order_number(0)

else

‘’’ do something

end if

Set partsDB = New NotesDatabase(“”,“”)

call partsDB.open(“”, “partsdata.nsf”);

If Not (partsDB.IsOpen) Then

‘’ you do not have access to it, or the db does not exist

‘’ do something

End If

Set inv_v = partsDB.GetView(“invbyorder”)

if (inv_v is nothing) then

‘’ view is not there, do something

end if

Set inv_items = New NotesRichTextItem(doc,“inv_items”)

'SetTable

Call GetAllItems(“Order”)

'CloseTable

Exit Sub

ErrorHandler:

Call ErrorHandler(“GetOrderItems”)

End Sub