I am new to Lotus notes and also lotus script but I have been learning along the way with tutorials provided. However, I am not too confident yet and needed help. I definitely know that this site is an excellent site that queries get answered and alot of help come from here and therefore am posting my queries from time to time.
I have created a script to return documents counts for an embebed view on a form. I would like the script to return the number of documents in the embeded view and return the value in a field called dcount. The embeded view contains a list of forms which are seperate from the parent form but a child to the parent form. What I would like to accomplish is to stop users from creating new child once they reach the maximum number allowed. I have a field on the parent form called maxnumber that I specify how many forms (forms contained within the embeded view) are allowed to be created. Once the max number is reached then a prompt must be displayed when users click on the new button to inform users that max number is reached. Below is the code that is created so far but I need some more assistance to complete it and get it working.
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
Dim doc As NotesDocument
Dim count As Variant
'Dim count As Integer
'count = 0
Set db = session.CurrentDatabase
Set view = db.GetView("LeasebyTenant")
Set vc = view.AllEntries
Set entry = vc.GetFirstEntry()
While Not (entry Is Nothing)
Set doc = entry.Document
Set entry = vc.GetNextEntry(entry)
'count = count + 1
Wend
'doc.DocCount=entry.ChildCount
'Set count=doc.DocCount
count = entry.ChildCount
If count <>Null Then
If Count => doc.maxnumber Then
Messagebox "Maximum number of documents created."
Exit Sub
End If
Call workspace.ComposeDocument( "", "", "Lease" )
End If
Thanks for your help. I tried your code and it gave a total that is more than the responses. The documents counted should have been the ones embeded on the main form or parent form but instead it seems like it is counting everything in that view and not just the ones selected for that embebed view. Is there a way around it?
Presumably the embedded view in your form showing the child documents is a single category view … that is the view in the DB is categoriesed and the view embeeded in the form only shows some of these docs based on a key value from the form.
Supposing the form only showed child docs for a tenant whose tenant ID was ABC. The field ABC must be some where on the parent form and the formula for the single category view would be the name of the field containing the TenantID.
Therefore your lookup to get the count of only values from child docs whose parent is TenantID=ABC (the key field in this case) would be
I have a view that select all of the child form and in that view I have 6 columns. Column 1 is the document id field for the parent form (Common in both forms, parent and child).
So what you have said is correct accept that I have 6 columns created and all columns displayed in the embebed view.
What is the name of the field that has the ID field in the form and what is its data type?
Also are the columns for the view categorised. If column one is not categorised then try column two possibly.
Either post the code you are using for the lookup on your form or else if you can send me a small copy of your databae with the form, and the view i can sort it out for you. either that or we could do an IRC chat, resolve it that way and then post the results here.
I have to go home now, my wife is waiting but I will look for your post in the morning. I am in NZ so we are GMT + !2 hours.
If the documents that you want count are all children of the document that you are on, then why not just use the NotesDocument.Responses collection? It has a Count property that gives you the info you are looking for.