Carrying data from view to new record.

Am trying to convert some code I have used in the past which captured some fields from a record when saved and opened a new record and dropped in that data. I want to do a similar thing here, but now it will be the user selects a record from a view and then clicks a New Record button and the fields in the code will be carried over to a new record of the same type. This is in an effort to save on data entry time when all the data will normally be the same. I have each field as editable with the field name as the default value. The user may need to override some of the data which is why they are editable. Here is what I have so far, but not sure how to link it to the record in the view.

Joe

Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace          
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc, newdoc As NotesDocument
      Dim linkdoc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Dim Item As NotesItem
      Dim View As NotesView
      Set uidoc = workspace.CurrentDocument
      Set db = session.CurrentDatabase
      Set doc= uidoc.Document
      Set newdoc = db.CreateDocument
      Set View = Current.View
      
      newdoc.office_num = doc.office_num(0)
      newdoc.agency = doc.agency(0)
      newdoc.city = doc.city(0)
      newdoc.state = doc.state(0)
      newdoc.contact = doc.contact(0)
      newdoc.Phone = doc.Phone(0)
      newdoc.Form = "OTS Office Contact Log"
      Call uidoc.Save
      Call uidoc.close
      
      workspace.EditDocument True, newdoc
End Sub
jforget1Asked:
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.

Sjef BosmanGroupware ConsultantCommented:
Conditions: the button is clicked from a view, and only one document is selected...

You need to add:

    If session.UnprocessedDocuments.Count!=1 Then
        MessageBox "Please select 1 document"
        Exit Sub
    End If
    Dim viewdoc As NotesDocument
    Set viewdoc= session.UnprocessedDocuments.GetFirstDocument

and viewdoc is the document you can fetch your data from
0
jforget1Author Commented:
Dropped in your add, but now I get an error on the open of the database. Not a member: UNPROCESSEDDOCUMENTS

I added your code as follows.

Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace          
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc, newdoc As NotesDocument
      Dim linkdoc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Dim Item As NotesItem
      Dim View As NotesView
      Set uidoc = workspace.CurrentDocument
      Set db = session.CurrentDatabase
      Set doc= uidoc.Document
      Set newdoc = db.CreateDocument
      Set View = Current.View
      
      If session.UnprocessedDocuments.Count!=1 Then
            Messagebox "Please select 1 document"
            Exit Sub
      End If
      Dim viewdoc As NotesDocument
      Set viewdoc= session.UnprocessedDocuments.GetFirstDocument
      newdoc.office_num = doc.office_num(0)
      newdoc.agency = doc.agency(0)
      newdoc.city = doc.city(0)
      newdoc.state = doc.state(0)
      newdoc.contact = doc.contact(0)
      newdoc.Phone = doc.Phone(0)
      newdoc.Form = "OTS Office Contact Log"
      Call uidoc.Save
      Call uidoc.close
      
      workspace.EditDocument True, newdoc
End Sub
0
p_parthaCommented:
it';s db.unprocesseddocuments,

Points for sjef :)

Partha
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Steve KnightIT ConsultancyCommented:
Could you just use the 'formulas inherit values from selected document' form property..... admitedly your way gives you more control mind...

Steve
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
Sjef BosmanGroupware ConsultantCommented:
Hi bro, me deeply ashamed... :$
0
Steve KnightIT ConsultancyCommented:
Both ways have their place :-)

Steve
0
jforget1Author Commented:
Now the error opening the DB is

Type Suffix does not match data type: COUNT

I swapped in DB for Session in the 2 spots above.
0
Steve KnightIT ConsultancyCommented:
use <> for not equal != is formula language and ! is a typing character for variables :-)
0
jforget1Author Commented:
OK i changed the not equal sign, when I run through debugger I get an object variable not set error on Set doc=uidoc.Document. I tried remarking that line out and reran the code. Now it is a Variant does not contain an object error on the line Set View = Current.View
0
p_parthaCommented:
Just check whether the code is in click event , or some other event also

partha
0
Sjef BosmanGroupware ConsultantCommented:
Aaaaaaargh!! It's Friday, once again...

There is no doc yet, so you did right to comment that line out. Do the same with the line with Current.View .
0
Steve KnightIT ConsultancyCommented:
Current.View should be (can't remember and haven't got notes open: workspace.currentview or maybe session.currentview

You don't need to the set doc= bit because you aren't using it.

Then further down you are getting viewdoc but using doc to set the newdoc fields.  They should all be viewdoc instead I guess.

0
Steve KnightIT ConsultancyCommented:
Good point, not using currentview either is it :-)
0
jforget1Author Commented:
Ok I am getting farther through the code, but I am now getting a  Variant does not contain an object error on the  newdoc.office_num = doc.office_num(0) line, I think because I have remmed out the doc line above it.
0
Steve KnightIT ConsultancyCommented:
Change them to viewdoc instead of doc.
0
jforget1Author Commented:
OK I think it is almost perfect, I have to rem out the Call doc save and close statements at the end of the code. One last thing I wonder if can be added. Right now when I do this, it does open the new doc and carry over the data, but it stays on the view and the new doc is one tab over. I wonder if code can be added to have it move over to the new record at the end of this process so the user is looking at the new record.  I know there will be people who keep clicking the button because they do not see that the new record has been created.
0
Sjef BosmanGroupware ConsultantCommented:
The focus... Hard to handle within Notes. Do you use frames in your application?

I'd also like to suggest to try dragon-it's solution, i.e. with the inherited field values. When you give each field in the document a default value of the field from the document in the view, it is supposed to work very easily. No coding whatsoever. It's just a @Command([Compose]; "yourform") and all fields to be copied must have a default value. Only once the values from the document in the view will be used, when setting the default values. Even fields with the same name should have a formula, so if the field XXX appears in both forms, it must have a default formula XXX.
0
jforget1Author Commented:
I just tried the inherit values method, but that does not seem  to work pulling the values when selected in a view. It will do it if I am in a record, what I think I may do is put another button at the doc level and advise the users to open the record first and then click new. I think this will work.

Thanks for the help.

Joe
0
jforget1Author Commented:
Thanks to all for the help, learned a couple ways to make this work.
0
Steve KnightIT ConsultancyCommented:
No problem, thanks for the points. It should work fine from the view level BTW?

Steve
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.