Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if document variable set 1

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
Here's what's up:

We have a leave accounting system. One of the fields in the document is DEPARTMENT. All of the views are based on DEPARTMENT so the supervisor of the department can see all the leave requests from that department. The field in the document is populated from the Notes Address database. However, in a recent move, we reorganized the departments and now I need to go back into the leave accounting database and update all the departments. So I have written a LotusScript agent that will get the name from the Leave Accounting database document, open the Notes Address database, find that person's name, get their new department and update the leave accounting with the new department.

The reason for this update is that there are still pending leave requests that the supervisor's can't see in the view since they have a different department name.

However, we have leave requests for people who no longer work here. So when I try to get the information from the Notes Address book there is no person who matches. What property or method do I need to use to see if a variable has been initialized?

Here's the script:

Code:
Sub Initialize
  Dim session As New notessession
  Dim db As notesdatabase
  Dim collection As notesdocumentcollection
  Dim doc As notesdocument
  Dim count As Long
  Dim newdepartment As NotesItem
  Dim olddepartment As NotesItem
  Dim LeaveName As Variant
  Dim strName As String
	
	
  Dim maildb As NotesDatabase
  Dim mailview As NotesView
  Dim maildoc As NotesDocument
	
	
	
  Set maildb = New NotesDatabase( "domino1", "names.nsf" )
  Set mailview = maildb.GetView( "People" )
	
  Set db=session.currentdatabase
  Set collection=db.AllDocuments

  searchFormula$ = "Status != ""Approved"" & Status != ""Rejected"""
  Set collection = db.Search(searchFormula$,Nothing,0) 
	
	
  for count=1To collection.count
    'assign leave document to doc
    Set doc=collection.getnthdocument(count)		
    'get mail information based on name to get new division for leave document
    LeaveName = doc.GetItemValue("Name")
    If Cstr(LeaveName(0)) <> ""  Then		
      If Instr(Cstr(LeaveName(0)), "CN") = 0 Then
        strName = Strright(Cstr(LeaveName(0)), " ") & " , " & Strleft(Cstr(LeaveName(0)), " ")
				
        Set maildoc = mailview.GetDocumentByKey(strName) 
[COLOR=red]
'Here is where I'm having the problem.  If there is no matching document and maildoc hasn't been set to anything, I want to move to the next leave document.[/color]			
        If maildoc [COLOR=red]is SOMETHING[/color] Then
          Set newdepartment = maildoc.GetFirstItem( "Department" )
          Set olddepartment = doc.ReplaceItemValue("Department", newdepartment)			
        End If
      End If
    End If
  Next
End Sub

Leslie
 
You need to use the HasItem method of the NotesDocument.

Pascal.
 
I knew there's was something and that you would know!

Thanks!

me

Leslie
 
:eek:(
That didn't work after all.

Here's what's happening. The variant LeaveName gets initialized from the Leave Document Name field. Let's say Debbie Garcia. Then I change it to a string and assign it to strName and now its: Garcia , Debbie.

Then I pass strName to the Notes Address Book. It returns a document that matches the name.

Next Leave document Name field = Debbie B. Garcia, when I add the comma it becomes:

strName = B. Garcia, Debbie

When I pass this name to the Notes Address book there is no matching document, so maildoc is not assigned anything. So when I get to the maildoc.HasItem line, the code still fails with the error "Object variable not set". Now in this case, there's no match because the name is passed incorrectly, but I will be processing documents for terminated employees and they will also not be found in the Notes Address book.

So, how can I detect if the object variable has been set (ie I've found a matching document in the Notes Address book and maildoc is something!)?

Thanks

Les

 
Indeed, I got it wrong. You're not checking a field value, you need to check for the existence of the document.

In this case, you want to check that the doc is not inexistant, in other words you want this :
Code:
If not(maildoc is nothing) Then

That will do the trick.

I got focused on your field problem, and I missed checking where maildoc was from. Sorry :).

Pascal.
 
I tried something like that but had the syntax wrong. Thanks!

les
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top