I am working on a view action to create a Group document in the user’s Personal Address book, using the NotesID field in the selected documents. It is labeled “Create Group From Selected”
As you can see in the following lotusscript snippet, I used session.AddressBooks to get the NABs, then Forall b… to examine each one. I find the names.nsf that is also a private address book, and want to create the list here. However, the variable b gets a type mismatch error when I try to copy the document to the NAB that it represents. It does not mind giving me the filename, server, etc on b as if it is a NotesDatebase, but will not CopytoDatabase. I tried creating another New NotesDatabase just for the copying, but got the message that the db was already opened (as b) when I tried to copy to it. BTW, the debugger identifies b as a Variant.
Here is the code…Any Suggestions?
’ Find the personal address book names.nsf, create group document, and copy it to the PAB
Forall b In session.AddressBooks
Call b.Open( “”, “” )
If b.FileName = “names.nsf” And b.IsPrivateAddressBook Then
Messagebox( b.Title )
Set listnote = New NotesDocument(db)
listnote.ListName = listname
listnote.ListDescription = listdescription
listnote.Members = idlist 'get entire list
listnote.Form = "Group"
listnote.Type = "Group"
Call listnote.CopyToDatabase(b)
Messagebox( "Group list created in " + b.Title)
’ Try instantiating another db
'Set PAB = New NotesDatabase( b.Server, b.Filepath )
'Call PAB.Open( “”, “” )
'Call listnote.CopyToDatabase(PAB)
'Messagebox( "Group list created in " + PAB.Title)
Subject: RE: Type Mismatch Error on copying to Address book
Oh, sorry, I just posted the block related to finding and copying to the Address book. Object db is set to session.CurrentDatabase. Here is the entire sub:
Sub Click(Source As Button)
' Creates a group list document and copies it to the user's Personal Address Book
Dim session As New NotesSession
Dim db As NotesDatabase
Dim PAB As NotesDatabase
Set db = session.CurrentDatabase
Dim note As NotesDocument
Dim listnote As NotesDocument
Dim books As Variant
Dim ws As New NotesUIWorkspace
Dim uiview As NotesUIView
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim item As NotesItem
Dim abname As NotesName
Dim idlist( ) As String
Dim cnt As Integer
Dim listname As String
Dim listDescription As String
Dim dateTime As New NotesDateTime( "" )
dateTime.LSLocalTime = Now
' Get the list name to be used - default to current date & time
listname = "PRTT " + datetime.LocalTime
listname = Inputbox$ ("Type the group name.", "Group Name?", listname)
If listname = "" Then
Messagebox "Action cancelled.", 0+16, "Action canceled." 'MB_OK+MB_ICONSTOP
Exit Sub
'<----------------
End If
' Collect the list of Notesids from the selected documents
cnt = 0
Set uiview = ws.CurrentView
Set dc = uiview.Documents 'set collection to selected documents in current view
If dc.Count = 0 Then
Messagebox "No documents selected.", 0+16, "Action canceled." 'MB_OK+MB_ICONSTOP
Exit Sub
'<----------------
Else
Redim idlist (1 To dc.Count)
Set doc = dc.GetFirstDocument
While Not (doc Is Nothing)
cnt = cnt +1
If doc.HasItem ("ResourceNotesID") Then
Set abname = New NotesName( doc.ResourceNotesID(0))
idlist( cnt) = abname.Abbreviated 'puts abbreviated name into list
End If
Set doc = dc.GetNextDocument (doc)
Wend
'Messagebox idlist(1), 0+64, "First ID"
End If
' Find the personal address book names.nsf, create group document, and copy it to the PAB
'books = session.AddressBooks
Forall b In session.AddressBooks
Call b.Open( "", "" )
If b.FileName = "names.nsf" And b.IsPrivateAddressBook Then
Messagebox( b.Title )
Set listnote = New NotesDocument(db)
listnote.ListName = listname
listnote.ListDescription = listdescription
listnote.Members = idlist 'get entire list *************?
listnote.Form = "Group"
listnote.Type = "Group"
Call listnote.CopyToDatabase(b)
Messagebox( "Group list created in " + b.Title)
' Try instantiating another db
'Set PAB = New NotesDatabase( b.Server, b.Filepath )
'Call PAB.Open( "", "" )
'Call listnote.CopyToDatabase(PAB)
'Messagebox( "Group list created in " + PAB.Title)
Exit Sub
Subject: RE: Type Mismatch Error on copying to Address book
Actually, I was sort of wondering why you create listnote in database “db”, although you never save it in “db” but then you copy it to “b”. Seems rather convoluted - why not just create it in “b” directly?
As I stated in my post, I would add a line making sure that PAB is open using the IsOpen property before trying to create a new NotesDocument object. If you don’t check first, it will bomb if you try to create a new document object from an unopened database object.
Better to be safe than sorry, even though it looks like the target db will always be open when you run this code (since the variant b and NotesDatabase object PAB are in fact references to the same object.)
Subject: Type Mismatch Error on copying to Address book
I think the reason you are getting the type mismatch is because of b being a variant in the debugger. I think you are on the right track with the PAB idea because in that regard you are setting PAB equal to a NotesDatabase object and not a variant, which could be anything.
What I would do is add this line before calling PAB.Open(“”,“”):
If Not PAB.IsOpen then
Call PAB.Open("","")
End If
This way, you can check if it is open, and if not, then open it. (Assuming you have access to the db of course!)
ADDENDUM: After thinking about it, the fact that the debugger lists b as a variant is absolutely your problem. The CopytoDatabase method accepts only a NotesDatabase object as a parameter. Since a variant can be anything, it won’t allow you to pass it as a parameter. So you have one of two choices–1. use the technique i listed above or 2.) create a document using this method: set newDoc = b.CreateDocument (which will work since it is calling the method, not being passed) and populate newDoc and save. If you want this document copied to the db object, you can use CopyToDatabase, because db is not a variant, it is a NotesDatabase object. I would probably do technique #2 myself, but whatever you are more comfortable with.