Calling 2 Subroutines To Create 1 Document

Can someone help me with this? I’m trying to call 2 subs, which are working, and import the data from both into one document. This code is in ‘Initialize’. All I get is data from Dept 50. Thanks to Matt for getting me this far!

If Date <> “” Then

	Call Dept50

End If

Goto Finish



If Date <> "" Then

	Call Dept56

	

End If

Goto Finish

Finish:

Detdoc.form = "Details"

success = detdoc.Computewithform(True, True)	

Call detdoc.save(True,True)

Msgbox "Document Created"

Exit Sub

Subject: Calling 2 Subroutines To Create 1 Document

To make your doc a global like that I think you have to Dim it in Declarations, then you can cast it Initialize.

Instead you could either…

Change these subs into FUNCTIONS that return your value. This assumes it adds a simple thing to the doc like a string or variant or something. (I.E., doc.MyValue = Dept56() )

Or pass your doc into the subs and have them add to it. (I.E., Call Dept56(doc) )

Make sense?

Subject: RE: Calling 2 Subroutines To Create 1 Document

Brian,

Can you elaborate on passing into the Subs?

Subject: RE: Calling 2 Subroutines To Create 1 Document

Sub myMainSub

OnError goto ErrHandle



Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = New NotesDocument ( db )

doc.Form = "Details"



If Date <> "" Then

	Call Dept50(doc)

	Call Dept56(doc)

End If



if doc.ComputeWithForm(True, True) then

	Call doc.save(True,True)

end if



Goto Cleanup

ErrHandle:

Msgbox "There was an error: " & Error$

Exit Sub

Cleanup:

Msgbox "Document Created"

Exit Sub

Private Function Dept50 (doc as NotesDocument)

if (doc is nothing) then Error 1001, "Invalid Parameter"



Dim item As NotesItem

Set item = doc.ReplaceItemValue( "SomeField", "Some New Value" )

End Function

Private Function Dept56 (doc as NotesDocument)

if (doc is nothing) then Error 1001, "Invalid Parameter"



Dim item As NotesItem

Set item = doc.ReplaceItemValue( "SomeOtherField", "Some Other New Value" )

Subject: RE: Calling 2 Subroutines To Create 1 Document

Getting ‘Illegal Exit Sub’ when I try to save.Private Function Dept50 (doc As NotesDocument)

.

.

.

.

'connect to PI and pass username

flag =	con.ConnectTo("Server1", "password")

If con.GetError <> DBstsSUCCESS Then

	Messagebox con.GetExtendedErrorMessage,, con.GetError & " " & con.GetErrorMessage

Here =========> Exit Sub

End If

Subject: RE: Calling 2 Subroutines To Create 1 Document

Sorry, few typos. None of that was tested of course. Try…

Sub myMainSub

On Error Goto Errhandle



Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = New NotesDocument ( db )

doc.Form = "Details"



If Date <> "" Then

	Call Dept50(doc)

	Call Dept56(doc)

End If



If doc.ComputeWithForm(True, True) Then

	Call doc.save(True,True)

End If



Goto Cleanup

ErrHandle:

Msgbox "There was an error: " & Error$

Exit Sub

Cleanup:

Msgbox "Document Created"

End Sub

Subject: Calling 2 Subroutines To Create 1 Document

Woulnd’t you want

If Date <> “” Then

Call Dept50

Call Dept56

End If

Detdoc.form = “Details”

success = detdoc.Computewithform(True, True)

Call detdoc.save(True,True)

Msgbox “Document Created”

Exit Sub

Subject: Calling 2 Subroutines To Create 1 Document

Woulnd’t you want

If Date <> “” Then

Call Dept50

Call Dept56

End If

Detdoc.form = “Details”

success = detdoc.Computewithform(True, True)

Call detdoc.save(True,True)

Msgbox “Document Created”

Exit Sub

Subject: RE: Calling 2 Subroutines To Create 1 Document

Only getting Dept56 data, no Dept50.