Solved

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

Posted on 2004-08-16
13
835 Views
Last Modified: 2013-12-18
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
Comment
Question by:CL_Quality_Assurance
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 9

Assisted Solution

by:HappyFunBall
HappyFunBall earned 300 total points
ID: 11810469
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
 

Author Comment

by:CL_Quality_Assurance
ID: 11810975
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
 
LVL 19

Assisted Solution

by:RanjeetRain
RanjeetRain earned 100 total points
ID: 11811252
Very simple. Bcoz when u call

Call doc.CopyAllItems(NewDoc,True)


at that time NewDoc is not a valid back-end document object.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 15

Assisted Solution

by:Bozzie4
Bozzie4 earned 100 total points
ID: 11811291
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
 
LVL 19

Assisted Solution

by:RanjeetRain
RanjeetRain earned 100 total points
ID: 11811354
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
 

Author Comment

by:CL_Quality_Assurance
ID: 11813081
I am trying all of your suggestions right now.  I will let you know how it goes.  Thank you for all of them.
0
 

Author Comment

by:CL_Quality_Assurance
ID: 11813282
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
 

Author Comment

by:CL_Quality_Assurance
ID: 11813489
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
 
LVL 9

Assisted Solution

by:HappyFunBall
HappyFunBall earned 300 total points
ID: 11813669
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
 
LVL 9

Accepted Solution

by:
HappyFunBall earned 300 total points
ID: 11813680
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
 

Author Comment

by:CL_Quality_Assurance
ID: 11813766
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
 
LVL 9

Assisted Solution

by:HappyFunBall
HappyFunBall earned 300 total points
ID: 11813814
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
 

Author Comment

by:CL_Quality_Assurance
ID: 11813859
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question