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
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) )
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
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