Help with code - trying to combine 2 different codes

I got part of this from another post. What I’m trying to do is have 2 prompts come up for the user to choose from then create a doc and show all the values. The form has text fields setup correctly to use on the new doc.

I need some help with my code. I saw two different codes with what I need but I’m having a hard time combining them.

Thanks for any help!


Sub Click(Source As Button)

'dim and set the objects

Dim session As New notessession

Dim dbCurr As notesdatabase

Set dbCurr = session.currentdatabase

Dim ws As New notesuiworkspace

Dim uidoc As notesuidocument

Dim docCurr As NotesDocument

Dim pickDoc As notesdocument

Set uidoc = ws.currentdocument

Dim newuidoc As notesuidocument

Set docCurr = uidoc.document

Dim getdoctitle As Variant, doctitle As String

Dim yearnums(3) 			As Variant

Dim yearvals(3)

Dim i As Integer

Dim pickview As notesview

Set pickview = dbCurr.getview("ShowLocation")

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

Dim e(300) As String,f(300) As String







    'what year do they want, present list of one year before current year, current year, and one year after	

    'or alternatively give them a picklist of year view	

YearNow = Year(Today)

yearnums(0) = YearNow + (-1)

yearnums(1) = YearNow

yearnums(2) = YearNow + 1





For i = 0 To 2

yearvals(i) = Cstr(yearnums(i)) 'convert the years to a string so that we can present it

Next



    'give them the view to choose a document from

server	 = dbCurr.server

dbname	 = dbCurr.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)



whichyear = ws.Prompt( PROMPT_OKCANCELLIST, "OSHA Form 300", "What year do you want to view?",	yearvals(1), yearvals)

If whichyear = "" Then

'they have pressed cancel

	Exit Sub

End If	



temp1 = Strleft(location, "^")

temp2 = Strright(location, "^")







    'create the document and open it





Dim OSHA300form As NotesDocument

Set OSHA300form = dbCurr.CreateDocument

OSHA300form.Form = "OSHA300form"

    Set doc = collection.GetFirstDocument

    Do Until doc Is Nothing





OSHA300form.selection = temp1 & "~" & whichyear

OSHA300form.formloc = temp1

OSHA300form.formyr = whichyear

OSHA300form.formstate = temp2

            OSHA300form.a = CaseLog

            OSHA300form.b = EmpFullName

            OSHA300form.c = EmpJobTitle 

            OSHA300form.d = CaseDate

            OSHA300form.e = CaseWhereOccurred

            OSHA300form.f = CaseInjuryorIllnes





End If

			

    Next

		

    Set doc = collection.GetNextDocument(doc)

Loop



Set NewUIDoc = ws.EditDocument(False, OSHA300form)



    End If

 

    End Sub

Subject: help with code - trying to combine 2 different codes

First, you have failed to use Option Declare. If you add this statement you will find you have numerous variables which are undeclared (and unassigned).

It appears you are trying to create some kind of report that contains information from multiple documents? But you have not done anything to locate the documents.

The test whichyear = “” is not the right way to tell whether the user pressed Cancel. Use isempty(whichyear). Dim whichyear as variant.

The line: Set doc = collection.GetFirstDocument

causes an error (probably something like “not an object”) because you have not assigned the variable collection.

These lines: End If

    Next

are incorrect because you don’t have a matching If and For above that point.

This statement: OSHA300form.a = CaseLog

and others like it, are incorrect because you have not previously assigned the variable CaseLog. I suspect you meant to read the field value CaseLog from the document in the loop, thus: OSHA300form.a = doc.CaseLog

However, even this is not correct, because if you process two documents, then the second time through the loop you will overwrite the value of the a field – your report will only contain data from the last document.

There are ways to do what you are trying to do with a report form, but you may be working too hard here. You can create an ad-hoc “report” of the selected documents by creating a categorized view that is categorized by your search key, and then using @SetViewInfo to limit display to just the category the user selected. An embedded view with a single-category formula would also work nicely, and you could put the two fields in comboboxes just above the embedded view, with a “go” button that just refreshes the form.

Or, you could make it really easy on yourself and just create a two-level categorized view and let the user navigate themselves to the category they want.

Subject: RE: help with code - trying to combine 2 different codes

Andre,

Thanks for the help! Sorry, my knowledge in Loutscript stinks right now. I’m working on it.

The part where I put osha300form.a = caselog, here is what I was trying to do. There is one form the user fills out. I’m trying to make a new report off that data, using another form. “A” is a text field on the new form. Osha300form is the name of the new form and caselog is a field on the first form where all the data comes through.

I tried embedded view with a single-categorized formula. That worked really good. My problem was that it wouldn’t print correctly. Really that’s the whole reason I need this report. On the new form, I had the data lined up with the embedded view but when printing, the embedded data view did not print right. The data would shift which made the report not good. I wish the embedded view would print just like you see it.

I figured, well, if I put text files on the new form, I can create a report, and the data will stay put and print correctly.

I want the the user to select a location, then select a year, then push that data from the orginal form to new form. The new form is a like a summary. Any suggestions?

Your help is appreciated!

Subject: RE: help with code - trying to combine 2 different codes

I’m not sure what you mean, you had the data “lined up” with the embedded view? Some data outside the view was lined up with data inside the view? The view was lined up with itself?

Are you sure the data was lined up, or was it just lined up on your screen? If you have a table that’s set to expand to margins, the cells will be different sizes if you change your window size (or print).

If you want to print data in tabular format, you should look at using an actual table with a row for each row of data. The redbook Domino Designer 6 A Developer’s Handbook contains a long chapter on programming rich text with many examples of generating exactly this kind of report. But I think you should get help with this. It doesn’t seem like you have a clear idea of what you are trying to do. Do you understand my point about accumulating information from the matching documents as opposed to replacing the information on each iteration so that you only end up with information about the last document?

Try to get a mentor who knows this stuff to talk you thru it. It’s not possible to go from where you are to where you need to be via Q&A in a forum.

Subject: RE: help with code - trying to combine 2 different codes

Yes, I need more training in LotusScript, I don’t disagree. I see what you mean where the doc overwrites the field. I don’t fully understand all LS yet and for some things formula language just won’t cut it.

I actually have the embedded view working. A button prompts the user for 2 values, then the document comes up with the embedded views based on the 2 values. All the data is there. The problem is that when printing, the embedded view shifts to the right. On my form, I have headings that describes what’s in the embedded view. When opening the doc, it looks fine but when previewing or printing, the embedded view moves to the right. Not all the data moves, just some of the data and it throws the whole document off. That’s really weird.

I tried putting the embedded view in a table thinking that would keep it in place but it still does the same thing.

Anyway, not sure what to do on this one.