Link to home
Start Free TrialLog in
Avatar of jkee54
jkee54Flag for United States of America

asked on

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?
Avatar of mbonaci
mbonaci
Flag of Croatia image

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.
Avatar of jkee54

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of jkee54

ASKER

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

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of jkee54

ASKER

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!