Copy data from one form to another, leave 2nd form open for edit

I have two forms.  Once a document is filled out from Form1, I want users to click a button and open a document from Form2.  One field's contents from Form1 needs to pass to Form2.

Then Form1 needs to close.
Form2 needs to be open in edit mode
Two more fields are filled out on Form2.
I want the user to click a button on Form2 that saves that document, closes it, and opens another document from Form2, and so on, until they are done, then there's another button that saves and exits.

I understand these are two pieces of code and thats ok, but they should be very similar, just a little different on buttons on both forms.

I have tried both formula language and lotusscript but my problem is making it work so that multiple tabs aren't left open.  I want Form1 to close after it's filled out - nothing more required here.  However there could be several documents from Form2 before they are done and I don't want the user left with that.

I thought maybe I could do it with user input via a dialog box, because the user really doesn't have to see the Form2 documents, they just need to populate those two fields.

Here is the formula language I have so far - but it keeps the wrong documents open, and I don't know how to tell how many @command([FileCloseWindow]) s to put because the number of form2 documents will vary.

This is in the Form1 Button
tmpFedEx := FedExNo;
@Command([Compose];"PolicyInfo");
'this is the field that needs to pass to Form2
@SetField("FedExNo";tmpFedEx);
'these next statements set several flags
@SetField("FEDEX";"Y");
@SetField("OD"; "Y");
@SetField("MULTPOL";"Y");
@UpdateFormulaContext
@Command([FileSave]);
@Command([FileCloseWindow]);

Can this be done cleanly with formula language?
jkee54Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbonaciCommented:
This would be much easier to do with LotusScript, post your LS code so we can help you with it.
Then you wont have to count how many docs are opened, because you'll have a reference to each of them in your code and simply call uidoc.Close.
0
jkee54Author Commented:
This is as far as I got with LS.  This script gives an "object variable not set" error.  It opens Form2 but doesn't copy the field over.  When I run the debugger it doesn't trap anything :(

Sub Click(Source As Button)
      Dim ws As New NotesUIWorkSpace      
      Dim uidoc As NotesUIDocument
      Dim targetDB As NotesDatabase
      Dim targetdoc As NotesDocument
      
      Set uidoc = ws.CurrentDocument
      Set targetDB = New NotesDatabase("mserver", "mydb")
      Set targetdoc = targetDB.CreateDocument
      targetdoc.Form = "PolicyInfo"
      targetdoc.FedExNo = uidoc.Document.FedExNo
      Call targetdoc.Save(True,fasle)
                      Call uidoc.Save(True,False)
                      Call uidoc.Close

      
End Sub
0
Sjef BosmanGroupware ConsultantCommented:
The documents of type Form2 are in a different database?
And what is fasle?
And did you know that the NotesUIDocument.Save method doesn't have 2 parameters?

I'd leave Form1 open (who cares), and I'd handle the creation of Form2-documents inside a dialog box. Not too difficult in LotusScript.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

mbonaciCommented:
OK, slow down. If you approach this the right way you'll end up with working code, but if you throw a few methods on a heap, without previously checking their definitions in Designer help, you'll end up with more comments like Sjef's.

You're on the right track.

Add error handling in any cohesive peace of code you write from now on (for starters you the plain and simple code posted bellow).
That way, even if you don't use debugger, you'll know in which line an error occured and which error it was.

Since debugger normally doesn't work on uidocuments created from script, to be able to debug the code of form2, turn debugger on just before you trigger an action whose code you want to debug, on that new document, not before it is created.

When you get stuck ask specific question and you'll be running that code on production very soon...
'Place this line on top of your code:
On Error Goto ErrHandler


'Place these lines at the end of your code (e.g. just above End Sub line):

leave:
	Exit Sub
ErrHandler:
	Print "Error " & Err & " " & Error$ & " -> <Replace this tag with your Form and sub/function name>: in line " & Erl
        Msgbox "Error " & Err & " " & Error$ & " -> <Replace this tag with your Form and sub/function name>: in line " & Erl, 16, "Error handler"
	Resume Next
End Sub

Open in new window

0
jkee54Author Commented:
OK, I'm getting there.  I like the dialog box idea.  This is what I ended up with, and it works... except is there a way to make the button retake the focus after the dialog box answers so the user just has to hit the Enter button?
Also I like the idea of an error handler but don't understand what formname should be there, and what do you mean by sub/function name?

Sub Click(Source As Button)
	Dim s As New NotesSession
	Dim db As NotesDatabase
	Dim ws As New NotesUIWorkspace
	Dim uidoc As NotesUIDocument
	Dim doc As NotesDocument
	Set uidoc = ws.CurrentDocument 
	uidoc.EditMode = True
	Set doc = uidoc.Document
	Set db=s.CurrentDatabase
	r1 = ws.Prompt (PROMPT_OKCANCELEDIT, "Policy",   "What is the client's POLICY NUMBER?")
	r2 = ws.Prompt  (PROMPT_OKCANCELEDIT, "ClientName",   "What is the client's NAME?")
	Dim doc2 As notesdocument
	Set doc2 = New NotesDocument (db)
	Call doc2.MakeResponse(doc) 
	doc2.form = "PolicyInfo"
	Call doc2.ReplaceItemValue("Policy",r1)
	Call doc2.ReplaceItemValue("ClientName",r2) 
	Call doc2.ReplaceItemValue("FedExNo", doc.FedExNo(0))
	Call doc2.ReplaceItemValue("DateFedEx", doc.DateFedEx(0))
	Call doc2.ReplaceItemValue("FedExSentBy",doc.FedExSentBy(0))
	Call doc2.Save(False, False)	
End Sub

Open in new window

0
mbonaciCommented:
It doesn't have to be form, I don't know where your code is, I presume it's on a form (design element) and that Sub Click is on some kind of button or action, so you should write:

Msgbox "Error " & Err & " " & Error$ & " -> Form PolicyInfo / Button CreateResponse / Sub Click: in line " & Erl, 16, "Error handler"

So that when your users get an error they can tell you the data from the message box so you know where the error exactly occurred, down to the line number.

This is the first stage of error handling. I create document in Log database for each error, send e-mail to admin for specific errors, use GetThreadInfo, ...
Sub Click(Source As Button)
        On Error Goto ErrHandler
        Dim s As New NotesSession
        Dim db As NotesDatabase
        Dim ws As New NotesUIWorkspace
        Dim uidoc As NotesUIDocument
        Dim doc As NotesDocument
        Set uidoc = ws.CurrentDocument 
        uidoc.EditMode = True
        Set doc = uidoc.Document
        Set db=s.CurrentDatabase
        r1 = ws.Prompt (PROMPT_OKCANCELEDIT, "Policy",   "What is the client's POLICY NUMBER?")
        r2 = ws.Prompt  (PROMPT_OKCANCELEDIT, "ClientName",   "What is the client's NAME?")
        Dim doc2 As notesdocument
        Set doc2 = New NotesDocument (db)
        Call doc2.MakeResponse(doc) 
        doc2.form = "PolicyInfo"
        Call doc2.ReplaceItemValue("Policy",r1)
        Call doc2.ReplaceItemValue("ClientName",r2) 
        Call doc2.ReplaceItemValue("FedExNo", doc.FedExNo(0))
        Call doc2.ReplaceItemValue("DateFedEx", doc.DateFedEx(0))
        Call doc2.ReplaceItemValue("FedExSentBy",doc.FedExSentBy(0))
        Call doc2.Save(False, False)

leave:
        Exit Sub
ErrHandler:
        Print "Error " & Err & " " & Error$ & " -> Form PolicyInfo / Button CreateResponse / Sub Click: in line " & Erl
        Msgbox "Error " & Err & " " & Error$ & " -> Form PolicyInfo / Button CreateResponse / Sub Click: in line " & Erl, 16, "Error handler"
        Resume Next
End Sub

Open in new window

0
Sjef BosmanGroupware ConsultantCommented:
Hmmm... Just some comments on the source code and the general idea. I'm not in favour of 2 Prompts, for it is not really a dialog box. Maybe it's too far-fetched to use a dialog box for only two fields. Read up on the DialogBox method in the Help database, it has some pretty powerful possibilities.

Do test r1 and r2 for their values! If either one is the empty string, you should probably not save the document.

Just as an additional precaution, may I suggest you use ComputeWithForm on doc2 before you save it? It'll set at least the $ConflictAction item, but you could set it yourself as well, using ReplaceItemValue.
0
jkee54Author Commented:
Thank you - my solution ended up being the prompts, and I added error handling and provided for blank answers.  I'm sorry I let this sit for a few days, you guys are always great!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.