• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 859
  • Last Modified:

Error: 'Object Variable Not Set' - not understanding why

Hello there.  I am requesting assistance with an Agent.  I am running into the error message of: 'Object Variable Not Set', and not understanding why it is occurring.  I have narrowed it down to where I believe that it is occurring (please scroll down to see where I put '????????????').  The code above the question marks (the Loop is new).  I may have upset code after this new Loop, but can not figure out how.

The business side of this application is the tracking of storage boxes in our warehouse.  These boxes contain financial, payment, legal documents.  

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase  
Set db = session.CurrentDatabase
Dim collect As NotesDocumentCollection
Dim doc As NotesDocument
Dim NewDoc As NotesDocument    
Dim uidoc As NotesUIDocument
Dim workspace As New NotesUIWorkspace
Dim answer As Integer
Dim item As NotesItem    
Dim datetime As NotesDateTime
Dim CurrentDate As New NotesDateTime("Today")
      
Dim viewkey As String
Dim docstatus As NotesDocument

Set collect = db.UnprocessedDocuments

'Check to see if a document was selected
If collect.count = 0 Then
Msgbox "You must first select a document.",48,"Check out a Box"
Exit Sub
End If
      
'Check to see if multiple documents were selected
If collect.count > 1 Then
Msgbox "Please select only one document.",48,"Check out a Box"
Exit Sub
End If
      
Set doc = Collect.GetFirstDocument    
'Check to see if an Invoice document was selected
If doc.Form(0) <> "RECORD RETENTION INFORMATION" Then
Msgbox "Please select a Document.",48,"Check out a Box"
Exit Sub
End If
      
'Display MessageBox
answer = Msgbox("This button will sign out a Box from storage, do you want to continue?", 36, "Check out a Box")
'Check to see if user pressed the Yes button  
If answer = 6 Then
Else
Exit Sub
End If
      
'Display MessageBox
answer = Msgbox("Is This a Rush Request?", 36, "RUSH REQUEST")
'Check to see if user pressed the Yes button  
If answer = 6 Then
Doc.Rush = "PLEASE RUSH Box Request"
Else
End If
If answer  <> 6 Then
Doc.Rush = "Box request"
Else
End If
      
'James' new code for updating status of box
'Status Update for documents      
viewkey =  doc.BoxNumber(0)  
Set view = db.GetView("ByBoxNum")
Call View.Refresh
Set docstatus = view.GetDocumentByKey(viewkey, True)
Set doc = view.GetFirstDocument()
      
'Obtain Box Number of the document updated - if any other documents in the database have this same Box Number, change their status to 'Checked Out'
Do While Not (doc Is Nothing)
If doc.BoxNumber(0) = docstatus.BoxNumber(0) Then    
doc.status = "Signed Out"
Else
End If      
Call doc.save(True,True)                            
Set doc = view.GetNextDocument(doc)
Loop
Msgbox "All Accounts associated with this Box Number have been updated to Checked Out.",48,"Check Out Confirmation"

???????????????
'Create a New Business Form document
Set uidoc = workspace.ComposeDocument( "", "", "Check out Activity" )
uidoc.AutoReload = False
Set NewDoc = uidoc.Document
      
Call doc.CopyAllItems(NewDoc,True)
'doc.Status = "Checked Out"
Set  doc.Outdate = CurrentDate
doc.InDate = " "
'Update selected New Business Form document
Call doc.save(True,True)
      
'Update New New Business Form document
Set     NewDoc.REQUEST_DATE = CurrentDate
NewDoc.STATUS = "Checked Out"
'NewDoc.Memoreqr= doc.InDate = " "
      
'Call uidoc.GotoField("Confirmout")
      
Dim UserName3 As New NotesName(session.UserName)          
'Set uidoc = workspace.EditDocument( True )
'Set Doc = uidoc.Document
Doc.MemoReq = UserName3.Common      
Call doc.save(True,True)
Dim mdoc1 As NotesDocument
Set mdoc1 = New NotesDocument( db )
mdoc1.Form = "Memo"
mdoc1.SendTo = "James L Bouse/Travelers"      
'mdoc1.SendTo = "CTCUSTSERV@IRONMOUNTAIN.COM"      
'mdoc1.CopyTo = "NATRET Email"
mdoc1.Subject = Trim$(Doc.Rush(0))
Dim UserName1 As New NotesName(session.UserName)
mdoc1.Body =  UserName1.Abbreviated & "  has requested the ENTIRE box# " & Doc.BoxNumber(0) & "  from " & Trim$(Doc.Code(0))_
& " containing " & Trim$(Doc.Account(0)) & " from Iron Mountain.  Please send this request to Travelers Home Office - 9CR. " 
Call mdoc1.Send( False )
Call uidoc.Reload
Call uidoc.save
Dim agent As NotesAgent
Forall a In db.Agents
If a.Name = "Clear the Checker Field" Then
Set agent  = a
Call agent.Run
Exit Forall          
End If
End Forall
End Sub

Just a note:  This is a programmer's code from years ago.  He is in another department now.  The only new part of the code is the performing of the Loop (which you guys helped me with).

Thank you.
0
CL_Quality_Assurance
Asked:
CL_Quality_Assurance
  • 6
  • 4
  • 2
  • +1
7 Solutions
 
HappyFunBallCommented:
Are you able to debug lotusscript from your client?  Try going to File > Tools > Debug Lotusscript to turn it on and then try running this agent.  You can step through each line to see which one is giving you the error.  Or since there is no error trapping here, just let the code run and when the error appears, the screen will switch to your debug window and it will be stuck on the line giving the error.

I took a quick look and only noticed this line that may give an error:  "Set  doc.Outdate = CurrentDate".  You don't need to use Set when setting an item value like this, but I'm not sure if that would be giving you the error.
0
 
CL_Quality_AssuranceAuthor Commented:
I am having a Monday...sorry, I knew this already.

When running the debugger, it stops at the line:
Call doc.CopyAllItems(NewDoc,True)
(six lines under my ???????????).

This is where I do not understand why.

0
 
RanjeetRainCommented:
Very simple. Bcoz when u call

Call doc.CopyAllItems(NewDoc,True)


at that time NewDoc is not a valid back-end document object.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Bozzie4Commented:
You can't create a document like that (you are mixing front-end and back-end  classes).  Better to build the backend document first, and open it

Do it like this:

???????????????
'Create a New Business Form document
'Set uidoc = workspace.ComposeDocument( "", "", "Check out Activity" )


Set NewDoc = db.createdocument()
newDoc.form="Check Out Activity"
     
Call doc.CopyAllItems(NewDoc,True)
'doc.Status = "Checked Out"
Set  doc.Outdate = CurrentDate
doc.InDate = " "
'Update selected New Business Form document
Call doc.save(True,True)
     
'Update New New Business Form document
Set     NewDoc.REQUEST_DATE = CurrentDate
NewDoc.STATUS = "Checked Out"
'NewDoc.Memoreqr= doc.InDate = " "
     
   
Dim UserName3 As New NotesName(session.UserName)          

'Set Doc = uidoc.Document
Doc.MemoReq = UserName3.Common      
Call doc.save(True,True)
Dim mdoc1 As NotesDocument
Set mdoc1 = New NotesDocument( db )
mdoc1.Form = "Memo"
mdoc1.SendTo = "James L Bouse/Travelers"      
'mdoc1.SendTo = "CTCUSTSERV@IRONMOUNTAIN.COM"      
'mdoc1.CopyTo = "NATRET Email"
mdoc1.Subject = Trim$(Doc.Rush(0))
Dim UserName1 As New NotesName(session.UserName)
mdoc1.Body =  UserName1.Abbreviated & "  has requested the ENTIRE box# " & Doc.BoxNumber(0) & "  from " & Trim$(Doc.Code(0))_
& " containing " & Trim$(Doc.Account(0)) & " from Iron Mountain.  Please send this request to Travelers Home Office - 9CR. "
Call mdoc1.Send( False )

' SAVE NEWDOC
Call newDoc.save(true, false )
' OPEN IT
set uidoc = workspace.editdocument( newdoc, true )

Dim agent As NotesAgent
Forall a In db.Agents
If a.Name = "Clear the Checker Field" Then
Set agent  = a
Call agent.Run
Exit Forall          
End If
End Forall
End Sub
0
 
RanjeetRainCommented:
Let's hope i didn't miss anything in your code.

YOu have a UIDOC. WHich gets intialized with a call to WS.Compose. This creates a front-end document. Fine! But this ain't a back-end document yet. So, a statement like

Set NewDoc = uidoc.Document

will never ever return a valid back-end document object. I do not if it can solve ur problem the way u want it, but try calling a save on the UIDoc soon before calling Set NewDoc = uidoc.Document. Or soon after calling Set uidoc = workspace.ComposeDocument( "", "", "Check out Activity" ).

In a nutshell, your code should be like:



Set uidoc = workspace.ComposeDocument( "", "", "Check out Activity" )
... ... ...
... ... ...
... ... ...

Call uidoc.save
Dim i as Integer
i = 0
Do while i < 1000
        DoEvents
Loop
... ... ...
... ... ...
... ... ...
Call doc.CopyAllItems(NewDoc,True)
... ... ...
... ... ...
... ... ...

Call uidoc.save


That dummy do... while loop just ensures that your document gets saved without a hitch even if there is a lateny on the server side.


0
 
CL_Quality_AssuranceAuthor Commented:
I am trying all of your suggestions right now.  I will let you know how it goes.  Thank you for all of them.
0
 
CL_Quality_AssuranceAuthor Commented:
I have tried Bozzie4 's code, however, still received the 'Oject Variable Not Set' at the same line, Call doc.CopyAllItems(NewDoc,True).

Now I am attempting RanjeetRain's code, though, a little over my head but I will attempt.
0
 
CL_Quality_AssuranceAuthor Commented:
I have tried RanjeetRain's code, however, just like Bozzie4's code, I am stopped at the Call doc.CopyAllItems(NewDoc,True) line and get my old friend error message.  Hmmm.  Any suggestions?

0
 
HappyFunBallCommented:
That makes sense because the loop above that line continues until 'doc' is Nothing.  So when you then try to call a method of the 'doc' object, as in doc.CopyAllItems(NewDoc, True), you're doc object is not set.

I think you want to change the 'doc' object you are using in your loop to some other name.  Perhaps docLoop or something.  That way, you won't overwrite the original 'doc' object which is set earlier in the code.
0
 
HappyFunBallCommented:
Just to be more clear, change the loop code to this:

Dim docLoop as NotesDocument
Set docLoop = view.GetFirstDocument()
     
'Obtain Box Number of the document updated - if any other documents in the database have this same Box Number, change their status to 'Checked Out'
Do While Not (docLoop Is Nothing)
If docLoop.BoxNumber(0) = docstatus.BoxNumber(0) Then    
docLoop.status = "Signed Out"
Else
End If    
Call docLoop.save(True,True)                          
Set docLoop = view.GetNextDocument(docLoop)
Loop
Msgbox "All Accounts associated with this Box Number have been updated to Checked Out.",48,"Check Out Confirmation"
0
 
CL_Quality_AssuranceAuthor Commented:
HappyFunBall, I was thinking about that - but being new to this coding and trying to add on to someone elses coding is causing this to be a big adventure, but I am attempting to learn as much as I can.
0
 
HappyFunBallCommented:
It's always an adventure when you start working with someone elses code.  Hardly anyone comments their code, and I'm including myself in that group.

So did the renaming help?
0
 
CL_Quality_AssuranceAuthor Commented:
HappyFunBall, that was it!  It runs now that I have renamed the doc to docLoop in the Loop (of course, I can call docLoop whatever I want to)

Thank you for your help.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now