Coll.count not returning

Does anyone know why the coll.count is not returning and creating the new doc? I ran the debugger and there is where it shows no docs are there although there are docs.

Sub Click(Source As Button)

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim db As NotesDatabase

Dim doc As NotesDocument, doc2 As NotesDocument

Dim a(300) As String,b(300) As String,c(300) As String,d(300) As String, e(300) As String, f(300) As String

Dim picklist As Variant

Dim key As String	 

Dim location As String

Dim coll As NotesDocumentCollection

Set db = session.CurrentDatabase

Set view = db.Getview("Report by Year")



 'give them the view to choose a document from

server	 = db.server

dbname = db.FileName

viewname = "showlocation"



 'give them a list of documents for selection	

picklist = ws.Pickliststrings(3,1,server,dbname,viewname, "Form","Select a Location.",3,"")

If Isempty(picklist) Then Exit Sub 'they have pressed cancel

location = picklist(0)

key = picklist(0)



Set coll = view.GetAllDocumentsByKey(key, True)



If coll.Count > 0 Then

	

	Set doc2 = db.CreateDocument

	doc2.form = "300Form"

	Set doc = collection.GetFirstDocument

	Do Until doc Is Nothing		

		

		doc2.a = CaseLog

		doc2.b = EmpFullName

		doc2.c = EmpJobTitle 

		doc2.d = CaseDate

		doc2.e = CaseWhereOccurred

		doc2.f = CaseInjuryorIllnes

		

		Set doc = collection.GetNextDocument(doc)

	Loop

	'Call doc2.save( True, True ) 

	Set uidoc = ws.EditDocument(False, doc2)	

	

End If

End Sub

Subject: coll.count not returning

Put some error trapping in your code and see what happens. Basic trapping around the entire sub, to see if any errors are thrown, and specific msgbox lines to see objects, etc. as they are being set.

(Also, unless it’s a typo, you’ve set your collection to be named “coll” but further down you’re referencing it as “collection” which will definitely cause a problem…

Sub Click(Source As Button)

on error goto errhand

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim db As NotesDatabase

Dim doc As NotesDocument, doc2 As NotesDocument

Dim a(300) As String,b(300) As String,c(300) As String,d(300) As String, e(300) As String, f(300) As String

Dim picklist As Variant

Dim key As String

Dim location As String

Dim coll As NotesDocumentCollection

Set db = session.CurrentDatabase

Set view = db.Getview(“Report by Year”) 'give them the view to choose a document from

server = db.server

dbname = db.FileName

viewname = “showlocation” 'give them a list of documents for selection

picklist = ws.Pickliststrings(3,1,server,dbname,viewname, “Form”,“Select a Location.”,3,“”)

If Isempty(picklist) Then Exit Sub 'they have pressed cancel

location = picklist(0)

key = picklist(0)

msgbox "Key = " & CStr(key)

Set coll = view.GetAllDocumentsByKey(key, True)

msgbox "coll.count is " & coll.count

If coll.Count > 0 Then

Set doc2 = db.CreateDocument

doc2.form = “300Form”

Set doc = coll.GetFirstDocument

Do Until doc Is Nothing doc2.a = CaseLog

doc2.b = EmpFullName

doc2.c = EmpJobTitle

doc2.d = CaseDate

doc2.e = CaseWhereOccurred

doc2.f = CaseInjuryorIllnes

Set doc = coll.GetNextDocument(doc)

Loop

'Call doc2.save( True, True )

Set uidoc = ws.EditDocument(False, doc2)

End If

errhand:

msgbox "Error at line " & erl & ": " & error

exit sub

End Sub

Subject: RE: coll.count not returning

The error shows this. Error at Line 30 Object Variable Not Set. I’m not sure what it’s referring to.

Subject: RE: coll.count not returning

Well, it’s finding the 2 docs, creating the doc, but not populating the fields. When the new doc is created, the prompt is saying error at line 0.

Subject: RE: coll.count not returning

I bet if you look, you’ll find that line 30 is this:

Set doc = collection.GetFirstDocument

It can’t set doc, because there is no object called collection. You’ve defined your NotesDocumentCollection as coll, not collection. You can’t change variable names midstream and expect the compiler to understand what you meant.

Subject: RE: coll.count not returning

I fixed that. Does it have to do with the field section at the bottom? I’m trying to take the fields from doc (collection) and put them on the new doc called doc2.

Thanks!

Subject: RE: coll.count not returning

Loyd,

This is your line 30. You can find the line and position in the bottom right corner of the IDE.

Set doc2 = db.CreateDocument

That being said, you loop through the docs and never save anything:

Do Until doc Is Nothing

doc2.a = CaseLog

doc2.b = EmpFullName

doc2.c = EmpJobTitle

doc2.d = CaseDate

doc2.e = CaseWhereOccurred

doc2.f = CaseInjuryorIllnes

Set doc = coll.GetNextDocument(doc)

Loop

So what ever your last doc in the collection has for data will populate doc2’s fields a-f.

What are you trying to accomplish exactly?

Shawn

Subject: RE: coll.count not returning

I’m trying to loop through the documents and grab those fields for each document that’s found and place all the field values on the new document for fields a-f, creating a list going down the report.

I’m missing something here…

Subject: RE: coll.count not returning

Sometimes it’s good to write some ‘pseudo-code’ or a flowchart of your data from start to finish and then code against that. it helps to keep you focused on larger projects.

You have this line up top:

Dim a(300) As String,b(300) As String,c(300) As String,d(300) As String, e(300) As String, f(300) As String

That creates these 300 position arrays that never get used.

If you want the field(s) on doc2 to contain all of the values on doc1 then you need to build a list of those values in each field.

Something like this will give you a comma seperated list of all doc1 values in the field on doc2.

Do Until doc Is Nothing

doc2.a = doc2.a(0) + ", " + CaseLog

doc2.b = doc2.b(0) + ", " + EmpFullName

doc2.c = doc2.c(0) + ", " + EmpJobTitle

doc2.d = doc2.d(0) + ", " + CaseDate

doc2.e = doc2.e(0) + ", " + CaseWhereOccurred

doc2.f = doc2.f(0) + ", " + CaseInjuryorIllnes

Set doc = collection.GetNextDocument(doc)

Loop

Now that you have all the data in the field set the filed property ‘Seperate Values when users enter’ to COMMA, then set the ‘Display Separate Values’ to NEW LINE and that should show each value in what will look like a column of data.

Align your fields in a row and you should at least see what you are trying to capture in a readable format.

HTH

Shawn

Subject: RE: coll.count not returning

Sorry,

Code should be like this…

Do Until doc Is Nothing

doc2.a = doc2.a(0) + ", " + doc1.CaseLog(0)

doc2.b = doc2.b(0) + ", " + doc1.EmpFullName(0)

doc2.c = doc2.c(0) + ", " + doc1.EmpJobTitle(0)

doc2.d = doc2.d(0) + ", " + doc1.CaseDate(0)

doc2.e = doc2.e(0) + ", " + doc1.CaseWhereOccurred(0)

doc2.f = doc2.f(0) + ", " + doc1.CaseInjuryorIllnes(0)

Set doc = collection.GetNextDocument(doc)

Loop

HTH

Shawn

Subject: RE: coll.count not returning

One last thing…

Doc will need to be changed to doc1 to distinguish it in the loop.

doc2.f = doc2.f(0) + ", " + doc1.CaseInjuryorIllnes(0)

Set doc1 = collection.GetNextDocument(doc1)

Loop

That should get you running.

Shawn

Subject: RE: coll.count not returning

I’m getting “Object Variable Not Set” for line 49.


Sub Click(Source As Button)

On Error Goto errhand



Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase



Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc1 As NotesDocument, doc2 As NotesDocument



Dim a As String,b As String,c As String,d As String, e As String, f As String

Dim picklist As Variant

Dim key As String

Dim location As String



server = db.server

dbname = db.FileName

viewname = "ShowLocation" 'give them a list of documents for selection



picklist = ws.Pickliststrings(3,1,server,dbname,viewname, "OSHA Form 300","Select a Location.",3,"")

If Isempty(picklist) Then Exit Sub 'they have pressed cancel



location = picklist(0)



temp1 = Strleft(location, "^")

temp2 = Strright(location, "^")



key = temp1



Msgbox "key = " & Cstr(key)



Dim view As NotesView

Set view=db.Getview("301 Incident Report by Year") 'give them the view to choose a document from

Dim collection As NotesDocumentCollection

Set collection = view.GetAllDocumentsByKey(key,True) 

Msgbox "collection.count is " & collection.count



If collection.count > 0 Then 

	

	Set doc2 = db.CreateDocument

	doc2.form = "300Form"

	

	Set doc = collection.GetFirstDocument

	

	Do Until doc Is Nothing

		

		doc2.a = doc2.a(0) + ", " + doc1.CaseLog(0)

		doc2.b = doc2.b(0) + ", " + doc1.EmpFullName(0)

		doc2.c = doc2.c(0) + ", " + doc1.EmpJobTitle(0)

		doc2.d = doc2.d(0) + ", " + doc1.CaseDate(0)

		doc2.e = doc2.e(0) + ", " + doc1.CaseWhereOccurred(0)

		doc2.f = doc2.f(0) + ", " + doc1.CaseInjuryorIllnes(0)

		

		Set doc1 = collection.GetNextDocument(doc1)

	Loop

	

      'Call doc2.save( True, True )

	Set uidoc = ws.EditDocument(False, doc2)

End If 

errhand:

Msgbox "Error at line " & Erl & ": " & Error

Exit Sub

End Sub

Subject: RE: coll.count not returning

Hi Loyd,

Try initialize the variable doc1 in line 45

Set doc1 = collection.GetFirstDocument

Joao Barbosa

Subject: RE: coll.count not returning

When I change that, it gives me this error: Line 47 Type Mismatch----------------------

Sub Click(Source As Button)

On Error Goto errhand



Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase



Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc1 As NotesDocument, doc2 As NotesDocument



Dim a As String,b As String,c As String,d As String, e As String, f As String

Dim picklist As Variant

Dim key As String

Dim location As String



server = db.server

dbname = db.FileName

viewname = "ShowLocation" 'give them a list of documents for selection



picklist = ws.Pickliststrings(3,1,server,dbname,viewname, "OSHA Form 300","Select a Location.",3,"")

If Isempty(picklist) Then Exit Sub 'they have pressed cancel



location = picklist(0)



temp1 = Strleft(location, "^")

temp2 = Strright(location, "^")



key = temp1



Msgbox "key = " & Cstr(key)



Dim view As NotesView

Set view=db.Getview("301 Incident Report by Year") 'give them the view to choose a document from

Dim collection As NotesDocumentCollection

Set collection = view.GetAllDocumentsByKey(key,True) 

Msgbox "collection.count is " & collection.count



If collection.count > 0 Then 

	

	Set doc2 = db.CreateDocument

	doc2.form = "300Form"

	

	Set doc1 = collection.GetFirstDocument

	

	Do Until doc1 Is Nothing

		

		doc2.a = doc2.a(0) + ", " + doc1.CaseLog(0)

		doc2.b = doc2.b(0) + ", " + doc1.EmpFullName(0)

		doc2.c = doc2.c(0) + ", " + doc1.EmpJobTitle(0)

		doc2.d = doc2.d(0) + ", " + doc1.CaseDate(0)

		doc2.e = doc2.e(0) + ", " + doc1.CaseWhereOccurred(0)

		doc2.f = doc2.f(0) + ", " + doc1.CaseInjuryorIllnes(0)

		

		Set doc1 = collection.GetNextDocument(doc1)

	Loop

	

      'Call doc2.save( True, True )

	Set uidoc = ws.EditDocument(False, doc2)

End If 

errhand:

Msgbox "Error at line " & Erl & ": " & Error

Exit Sub

End Sub