Create and edit document in another database

Hello,

I’m trying to do this:

open a document in one database, click the button that will create a document in another database, copy 3 fields from one document to another document in the second database and will remain opened so I can further edit that document.

I have this piece of code. I would be very thankfull if you could help me out with this one.

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim database2 As NotesDatabase

Dim view As NotesView

Dim doc2 As NotesDocument

Dim varName, varAcces As String

Dim uidoc As NotesUIDocument

Set uidoc = ws.CurrentDocument

varName = uidoc.FieldGetText( “Rpt_User” )

varAccess = uidoc.FieldGetText( “Rpt_ProblemDetails” )

Set database2 = session.getdatabase(“VALEOSH_KOS01/S/VALEO”, “Kosice\SAP-auth.NSF”)

Set doc2 = database2.CreateDocument

doc2.Form = “CreationSAPBW”

doc2.Editdocument(True) <— error occurs here. I checked the designer help but I didn’t help me

doc2.Demandeur = varName <— the passing of values is not working

doc2.Utilisateur = varName

doc2.Acces=varAcces

doc2.Justification = varAcces

'Call doc2.save(True, True) <— actually I don’t want to save the document but keep it opened for further editing

I tried this. The document is created in second database but the passing of the values of the fields is not working and. And ofcourse the document doesn’t remain opened for further editing which is wrong.

Any ideas?

thank you very much

Robert Hakala

Subject: Create and edit document in another database

Well, I think your error is occuring because you are trying to edit the back end document (doc2 is declared as Dim doc2 As NotesDocument) and you haven’t saved it yet. You can’t open something that doesn’t exist yet. Why don’t you move the code up that writes the values to doc2 up above the EditDocument line and then save it and then issue the EditDocument command?

Subject: RE: Create and edit document in another database

The document in another database was created, values were not passed, the same error occured.

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace	

Dim database2 As NotesDatabase

Dim view As NotesView

Dim doc2 As NotesDocument

Dim varName, varAcces As String	

Dim uidoc As NotesUIDocument



Set uidoc = ws.CurrentDocument

varName = uidoc.FieldGetText( "Rpt_User" )

varAccess = uidoc.FieldGetText( "Rpt_ProblemDetails" )



Set database2 = session.getdatabase("VALEOSH_KOS01/S/VALEO", "Kosice\\SAP-auth.NSF")

Set doc2 = database2.CreateDocument

doc2.Form = "CreationSAPBW"

doc2.Demandeur = varName

doc2.Utilisateur = varName

doc2.Acces=varAcces

doc2.Justification = varAcces

Call doc2.save(True, True)

doc2.Editdocument(True)

Any idea, please?

Subject: RE: Create and edit document in another database

Well, I don’t think you posted what the error was. That might help someone help you better if you add the information.

Assuming that varName was actually assigned a value, it looks like it should have passed the values over. The varAccess didn’t work because you didn’t spell it the same. You declared it as varAcces (only one s) but you assigned it a value by spelling it varAccess (two s’s).

You might want to add a temporay messagebox after varAccess to make sure that varName and varAccess are really getting assigned values. Or step through the code in the debugger.

And Spanish was right about EditDocument being a UI method so it won’t work on the backend document. You might try declaring another frontend document like Dim uidoc2 as NotesUIDocument and then assigned doc2 to it.

Set doc2 = uidoc2 and then using the editdocument command on uidoc2

Subject: Create and edit document in another database

Hi Robert.I think that the problem is the use of Editdocument in a method or properties of NotesDocument.

You can make doc2.Form = “CreationSAPBW”, because Form is a field of the document.

The method Editdocument is for NotesUIWorkspace:

Set uidoc = ws.EditDocument( True )

Set notesUIDocument = notesUIWorkspace.EditDocument( [editMode] , [notesDocument] , [notesDocumentReadOnly] , [documentAnchor$] , [returnNotesUIDocument] , [newInstance] )

Sorry for my english.

Subject: Create and edit document in another database

Hi,

You can only edit the document by accessing via ws class, where you can pass the value of doc forward to the workspace.

And you need to do the passing of values before you open it for editing - so your code is in the wrong order.

HTH,

Ranjan Returns

eg.:

Sub Initialize

Dim ws As New NotesUIWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim customerNumber As String

Set db = session.CurrentDatabase

Set view = db.GetView(“All Documents by CustomerNumber”)

customerNumber = Inputbox$(“Customer number”)

If customerNumber <> “” Then

Set doc = view.GetDocumentByKey(customerNumber, True)

If doc Is Nothing Then

  Messagebox "Customer # " & customerNumber,, _

  "Customer not found"

Else

'*****

  Call ws.EditDocument(true, doc)

'*****

End If

End If

End Sub

Subject: RE: Create and edit document in another database

Set view = db.GetView(“All Documents by CustomerNumber”)customerNumber = Inputbox$(“Customer number”)

If customerNumber <> “” Then

Set doc = view.GetDocumentByKey(customerNumber, True)

GetDocumentByKey? what key should I use when I’m trying to edit a document that does not exists yet?

Subject: RE: Create and edit document in another database

Hi,

My example was simply to show you how to do the edit the doc in the workspace. Your call was not right in the exmaple you posted. You can replace the ‘set doc =’ portion with your doc assignment that you’re using.

I’ve used this code several times…and it works a treat…

HTH

Ranjan Returns

Subject: RE: Create and edit document in another database

Thank you very much,

I don’t have that many experience yet so it took me a while to figure it out but it’s working now! Thank you very much for your advice, what a help!

the working code is here:

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace	

Dim database2 As NotesDatabase

Dim view As NotesView

Dim doc2 As NotesDocument

Dim uidoc2 As NotesUIDocument

Dim varName, varAcces As String	

Dim uidoc As NotesUIDocument



Set uidoc = ws.CurrentDocument

varName = uidoc.FieldGetText( "Rpt_User" )

varAcces = uidoc.FieldGetText( "Rpt_ProblemDetails" )



Set database2 = session.getdatabase("VALEOSH_KOS01/S/VALEO", "Kosice\\SAP-auth.NSF")

Set doc2 = database2.CreateDocument

doc2.Form = "CreationSAPBW"

doc2.Demandeur = varName

doc2.Utilisateur = varName

doc2.Acces=varAcces

Call doc2.save(True, True)

Call ws.EditDocument(True, doc2)

pretty simple for someone but took me a few days to figure this one out…

thanks to everybody

Robert Hakala