Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to Check if Lotus Notes open & user logged in?

Status
Not open for further replies.

lollyjar

Programmer
Aug 3, 2003
29
GB
Is there a way to check if Lotus Notes is open and that the user is logged on (Access97)? I am e-mailing succesfully, but if the user is not logged on to notes, I get the following two errors:

"The NOTES.ini file cannot be found on the search path (PATH): notes.ini" (This one appears to be a Windows or Lotus Notes Error)

then

"Run-time error '429' ActiveX component can't create object" (this one is an MSAccess Error)

at the following command

Set Session = CreateObject("Notes.NotesSession")

I could use error handling, but is there a better way?

Cheers,

(I have also asked this in VB forum, but no response as yet)
 
can you please post the code, that you use to send your mail via LotusNotes?
I'm pretty sure, that we could find a solution for you (myself I'm using a function that opens LN if not yet opened ...)

Bye,
fly

Martin Serra Jr.
 
Hi Martin,

Thanks for the response ... The code I am using is the same as has been floating around in various threads in this forum:


Code:
'Public Sub SendNotesMail(Subject as string, attachment as string,
'recipient as string, bodytext as string,saveit as Boolean)
'This public sub will send a mail and attachment if neccessary to the
'recipient including the body text.
'Requires that notes client is installed on the system.
' This code was borrowed from [URL unfurl="true"]http://www.fabalou.com/VBandVBA/lotusnotesmail.asp[/URL]
Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean, blnDraft As Boolean)
'Set up the objects required for Automation into lotus notes
    Dim Maildb As Object 'The mail database
    Dim UserName As String 'The current users notes name
    Dim MailDbName As String 'THe current users notes mail database name
    Dim MailDoc As Object 'The mail document itself
    Dim AttachME As Object 'The attachment richtextfile object
    Dim Session As Object 'The notes session
    Dim EmbedObj As Object 'The embedded object (Attachment)
    'Start a session to notes
    Set Session = CreateObject("Notes.NotesSession")
    
    'Next line only works with 5.x and above. Replace password with your password
    'Session.Initialize ("password")
    'Get the sessions username and then calculate the mail file name
    'You may or may not need this as for MailDBname with some systems you
    'can pass an empty string or using above password you can use other mailboxes.
    UserName = Session.UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    'Open the mail database in notes
    Set Maildb = Session.GETDATABASE("", MailDbName)
     If Maildb.ISOPEN = True Then
          'Already open for mail
     Else
         Maildb.OPENMAIL
     End If
    'Set up the new mail document
    Set MailDoc = Maildb.CREATEDOCUMENT
    MailDoc.Form = "Memo"
    MailDoc.sendto = Recipient
    MailDoc.Subject = Subject
    MailDoc.Body = BodyText
    MailDoc.SAVEMESSAGEONSEND = SaveIt
    'Set up the embedded object and attachment and attach it
    If Attachment <> "" Then
        Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
        Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
        MailDoc.CREATERICHTEXTITEM ("Attachment")
    End If
    
    If blnDraft = True Then
        'Save the document as a draft
        MailDoc.Save True, True
    Else
        'Send the document
        MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
        MailDoc.SEND 0, Recipient
    End If
    'Clean Up
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj = Nothing
End Sub
 
Hi again lollyjar,

attached is the function I use (it's also a modified version of one of the functions floating around the forums). I use it with Access 97 and it works fine (if LN is not started, it opens a LN session ...).
Try it out.

Code:
Public Function SendNotesMail(Subject As String, Attachment As String, _
Recipient As String, ccopy As String, urgency As String, BodyText As String, SaveIt As Boolean) As Boolean
'needs Lotus Notes Client 4.5.x or better

Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)

On Error GoTo err_SendNotesMail
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.copyto = ccopy
MailDoc.Importance = urgency
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
End If
'Send the document
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing

SendNotesMail = True
end_SendNotesMail:
Exit Function

err_SendNotesMail:
Select Case err.Number
Case 429:
MsgBox "Errordescription: " & vbCrLf & err.Description & vbCrLf & _
"Possible cause:" & vbCrLf & "Lotus Notes not installed", vbCritical, _
"Error on initialising LotusNotes"
Case Else:
MsgBox err.Description & err.Number, vbCritical, "Error Lotus Notes Mail"
End Select
Resume end_SendNotesMail

End Function

HTH,
fly


Martin Serra Jr.
 
Hi Again Martin,

Thanks for the post, however with your code, I get an identical error. It works fine if Lotus Notes is open and logged in, however if notes is closed, then the error arises.

Any ideas?

Cheers,
 
check out your references (go to a code window and then select "tools"->"references") for something like "Lotus Notes Automation Classes" or "OLE Automation"

HTH,
fly

Martin Serra Jr.
 
Hi Martin,

Thanks again, but yes I do have these references checked. Any thing else you can think of?

Cheers,
 
Hi again lollyjar,

I'm really sorry ... this might hurt ...
I suppose, there's something wrong with you LN installation.

Try to remove and reinstall LN.

Sorry again, no more suggestions from my side regarding your specific problem.

Bye,
fly

Martin Serra Jr.
 
"The NOTES.ini file cannot be found on the search path (PATH): notes.ini"
Have you tried to play with ChDir before starting the LN session ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

I had a go using ChDir to change the default directory to where the Lotus notes ini file resides, but it doesnt seem to help & I get the same errors. Any other ideas?

Cheers,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top