Review my code (only small)

Slowly teaching myself code still. Very slowly, and working on customising buttons which we already currently use for support purposes. The following is straight forward - returns the profile to the sender. In particular I’d be interested to see if all the dimming of UIdoc & workspace is neccessary to get the sender (“From”) value. Could see how else to get items from the current document. Would you change anything?

Dim s As New notessession

Dim db As notesdatabase

Dim doc As notesdocument

Dim itemRich As NotesRichTextItem



'Get the required profile document

Set db=s.currentdatabase

Set doc = db.GetProfileDocument("OutofOfficeProfile")



'Build the document to be returned to sender

Set maildoc=db.createdocument	

maildoc.form="memo"

maildoc.subject="Out of Office profile for " &  s.CommonUserName

Set itemRich=New NotesRichTextItem(maildoc,"body")

Call itemRich.AddNewline(3)

Call itemRich.appendtext("*******************************" & doc.form(0) & "******************************")

Call itemRich.AddNewline(1)

Forall item In doc.Items

	Call itemRich.appendtext(item.name & " : " & item.type & " - " & item.text)

	Call itemRich.AddNewline(1)

End Forall

'If user should choose Administrator use this;

’ recip = Inputbox("Administrator to send to; ")

'Otherwise ascertain the sender to reply to;

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim recip As Notesitem

Dim fromdoc As NotesDocument

Set uidoc = workspace.CurrentDocument

Set fromdoc = uidoc.document

Set recip = fromdoc.GetFirstItem("From")



'send the profile document

Call maildoc.Send(False, recip)



'display a box to say it has been sent

Dim recipstr As String

recipstr = fromdoc.From(0)

Messagebox("Profile has been sent to " & recipstr)



'close the document

Call uidoc.Close

Subject: Review my code (only small)

James,

If you are going to engage the UI and you aren’t going to use a form event to do it, then you are going to be stuck instantiating a NotesUIWorkspace and a NotesUIDocument object.

Does this script actually work? I see you are passing a Notesitem as a parameter for the Send method–according to the help it can only accept strings or a string array, not a NotesItem object.

Otherwise, it looks pretty solid to me.

Brandt

Subject: RE: Review my code (only small)

Hi Brandt, thanks for responding.

Yeah it does work. Getting the Send parameter was actually the bit I got stuck on as I kept getting Type Mismatch errors. As it is it works, but if there’s a better way I’m all ears!