Link to home
Start Free TrialLog in
Avatar of CL_Quality_Assurance
CL_Quality_Assurance

asked on

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.
SOLUTION
Avatar of HappyFunBall
HappyFunBall

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CL_Quality_Assurance
CL_Quality_Assurance

ASKER

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.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am trying all of your suggestions right now.  I will let you know how it goes.  Thank you for all of them.
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.
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?

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.