Solved

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

Posted on 2004-08-16
13
829 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
Comment Utility
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
Comment Utility
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
Comment Utility
Very simple. Bcoz when u call

Call doc.CopyAllItems(NewDoc,True)


at that time NewDoc is not a valid back-end document object.
0
 
LVL 15

Assisted Solution

by:Bozzie4
Bozzie4 earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I am trying all of your suggestions right now.  I will let you know how it goes.  Thank you for all of them.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:CL_Quality_Assurance
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now