This code will raise a user defined error 4101 if any problem occurs. If you don't catch it, the user will see it. To catch it, precede the call with an "ON ERROR 4101 goto MyHandler". In the handler, the error message can be accessed through $Error. You may want to collect error messages for analysis in a log or simply by emailing them somewhere. Due to the nature of this code, I'm reporting every error that could conceivably occur that I can think of.
Public Function GetCurrentLocation As NotesDocument
- Dim session As New notessession
- Dim books As Variant
- books =session.AddressBooks
- Forall b In books ' get users public address book
- If Not b.IsPublicAddressBook Then
- Call b.open("","")
- If b.isOpen Then
- Dim locations As NotesView
- Set locations=b.GetView("Locations")
- If Not locations Is Nothing Then
- Dim key As String
- key=session.GetEnvironmentString("Location",True)
- If key<>"" Then
- Dim index As Integer
- index=Instr(key,",")
- If index>0 Then key=Left(key,index-1)
- Dim location As NotesDocument
- Set location=locations.GetDocumentByKey(key,True)
- If Not location Is Nothing Then
- Set GetCurrentLocation=location
- Exit Function
- Else
- Error 4101, {Current location document not found.}
- End If
- Else
- Error 4101, {Unable to look up current location.}
- End If
- Else
- Error 4101, {Personal name & address book does not contain a "Locations" view.}
- End If
- Else
- Error 4101, "Unable to open personal name & address book"
- End If
- End If
- End Function
This was first published in September 2006