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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emergency..Need Some Help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2

Status
Not open for further replies.

jdwm2310

Technical User
Jul 26, 2001
396
US
I am sending a message from Access 97 using Lotus Notes. Everything seems to work smoothly the only problem I have is with the TO and CC. The TO should be controlled by a combobox "Routed To"; if the user selects someone from this box that person will be in the TO, I have CC to default at a specific email address...Could someone please take a look at my code...

[tt]Private Sub Send_Click()
DoCmd.SendObject acSendNoObject, , , Route_To, "HRHelpDesk@siac.com", , ("This ticket has been routed by the HR Help Desk"), ("Please contact the following employee: " & CallerName & " at : " & Telephone & ", after reviewing the following question: " & RequestedQuestion & " Thank you, " & UserName)
DoCmd.Close acForm, "HelpDeskCalls", acSaveYes
DoCmd.OpenForm "TicketOption"
End Sub[/tt]

This is my module:
[tt]Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, cc As String, BodyText As String, SaveIt 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 NotesDocument
Dim MailDoc2 As Object
Dim AttachMe As Object 'The attachment richtextfile object
Dim session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object Attachment
Dim CurrentDatabase As String
Dim NotesSS As New NotesSession
Dim NotesDb As New NotesDatabase
Dim SendFolder As String
Dim view As NotesView


On Error GoTo Errshow:


NotesSS.Initialize '"password" ' you can place your password here to go straight in if not logged in already

With NotesSS
Set NotesDb = .GetDatabase("Mail3/SIAC", "mail/jperez.nsf", False)
End With

With NotesDb
'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 = NotesDb
Set MailDb = session.GetDatabase("", MailDbName)

If Not (MailDb.IsOpen) = True Then MailDb.OPENMAIL

'Set up the new mail document
Set MailDoc = MailDb.CreateDocument
With MailDoc
.Form = "Memo"
.sendto = Recipient
.CopyTo = cc
.Subject = Subject
.Body = BodyText
.SaveMessageOnSend = SaveIt
.principal = "user account" '(if different to your default account name)
'.PutInFolder SendFolder, True '(if you need a copy in the sent folder)
End With

'Set up the embedded object and attachment and attach it
If Attachment <> &quot;&quot; Then
Set AttachMe = MailDoc.CreateRichTextItem(&quot;Attachment&quot;)
Set EmbedObj = AttachMe.EmbedObject(1454, &quot;&quot;, Attachment, &quot;Attachment&quot;)
MailDoc.CreateRichTextItem (&quot;Attachment&quot;)
End If
End With

'MailDoc.PutInFolder (SendFolder)

'Send the document
MailDoc.Send 1, Recipient


MsgBox &quot;Sent!&quot;, vbExclamation

Cleanup:

Set MailDb = Nothing
Set MailDoc = Nothing
Set AttachMe = Nothing
Set session = Nothing
Set EmbedObj = Nothing

Exit Sub

Errshow:
MsgBox (Err.Description)
GoTo Cleanup

End Sub [/tt]

Guys I really need your help...I am so close I could taste it...
 
Well what happens when you run it at the moment? You might try changing Route_To to Me.Route_To?

Cheers,

Pete
 
jd,
Calm down, you are getting your knockers in a twist & not thinking things thru!
You have a module for sending lotus notes. That is good. You realised you need that, however if you look at your code, you are not using it, you are just trying to use the sendobject command which will not work with Notes.
You need to change your code behind the send button to:

Private Sub Send_Click()
SendNotesMail &quot;This ticket has been routed by the HR Help Desk&quot;, &quot;&quot;, Route_To, HRHelpDesk@siac.com, &quot;Please contact the following employee: &quot; & CallerName & &quot; at : &quot; & Telephone & &quot;, after reviewing the following question: &quot; & RequestedQuestion & &quot; Thank you, &quot; & UserName, true
)DoCmd.Close acForm, &quot;HelpDeskCalls&quot;, acSaveYes
DoCmd.OpenForm &quot;TicketOption&quot;
End Sub

This should get you somewhere near.

Ben

BTW: I helped someone develop a lotus notes module that was similar, but not the same as this one! Could that person get back to me as I now can't find that code.


B ----------------------------------
Ben O'Hara
Home: bpo@RobotParade.co.uk
Work: bo104@westyorkshire.pnn.police.uk
Web: ----------------------------------
 
Ben,

I entered this:

[tt]SendNotesMail &quot;This ticket has been routed by the HR Help Desk&quot;, &quot;&quot;, Route_To, HRHelpDesk@siac.com, &quot;Please contact the following employee: &quot; & CallerName & &quot; at : &quot; & Telephone & &quot;, after reviewing the following question: &quot; & RequestedQuestion & &quot; Thank you, &quot; & UserName&quot;, True
DoCmd.Close acForm, &quot;HelpDeskCalls&quot;, acSaveYes
DoCmd.OpenForm &quot;TicketOption&quot;
End Sub[/tt]
But I am getting a compile error: syntax error...Any idea why?????
 
Guys,

Using the code I posted I am able to get to Lotus Notes, my subject and body text appears the only thing that doesn't appear is the To or CC section meaning that the user has to enter it mannually..I just wanted to share this maybe it could help...but at this point I am clueless...Thanks
 
There are some errors in your module.
Replace it with this one:

Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, cc As String, BodyText As String, SaveIt 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 NotesDocument
Dim MailDoc2 As Object
Dim AttachME As Object 'The attachment richtextfile object
Dim session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim CurrentDatabase As String
Dim NotesSS As Object
Dim NotesDb As Object

On Error GoTo Errshow:

Set NotesSS = CreateObject(&quot;Notes.NotesSession&quot;)

With NotesSS
Set NotesDb = .GETDATABASE(Mail3/SIAC&quot;, &quot;mail/jperez.nsf&quot;)
End With

With NotesDb
'Start a session to notes
Set session = CreateObject(&quot;Notes.NotesSession&quot;)
'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 = NotesDb.FileName
Set MailDb = session.GETDATABASE(&quot;&quot;, MailDbName)

If Not (MailDb.ISOPEN) = True Then MailDb.OPENMAIL

'Set up the new mail document
Set MailDoc = MailDb.CREATEDOCUMENT
With MailDoc
.Form = &quot;Memo&quot;
.sendto = Recipient
.CopyTo = cc
.Subject = Subject
.Body = BodyText
.SAVEMESSAGEONSEND = SaveIt
End With
'Set up the embedded object and attachment and attach it
If Attachment <> &quot;&quot; Then
Set AttachME = MailDoc.CREATERICHTEXTITEM(&quot;Attachment&quot;)
Set EmbedObj = AttachME.EMBEDOBJECT(1454, &quot;&quot;, Attachment, &quot;Attachment&quot;)
MailDoc.CREATERICHTEXTITEM (&quot;Attachment&quot;)
End If

End With

'Send the document
MailDoc.SEND 1, Recipient
Cleanup:

Set MailDb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set session = Nothing
Set EmbedObj = Nothing

Exit Sub

Errshow:
MsgBox (Err.Description)
GoTo Cleanup

End Sub


B ----------------------------------
Ben O'Hara
Home: bpo@RobotParade.co.uk
Work: bo104@westyorkshire.pnn.police.uk
Web: ----------------------------------
 
What gets highlighted when syntax error is displayed? You might have to put brackets around all your arguments to get rid of that syntax error.

Also use breakpoints to step through the code and check what is being passed to SendNotesMail and other sub procedures for the to: and cc: arguments I can't see what it might be at the moment

Cheers,

Pete
 
Guys,

This is what I have done so far, I changed my code to mirror the one Ben posted. Pete I followed your suggestions I put brackets around the arguments..but now i get a compile error: expected variable or procedure, not module???/
 
What is highlighted? And what is the name of the module that all this code is sitting in?

Cheers,

Pete
 
So I rename by module to Send...and now I get type mismatch:
[tt]Private Sub Send_Click()
SendNotesMail &quot;This ticket has been routed by the HR Help Desk&quot;, &quot;&quot;, Me.Route_To, &quot;HRHelpDesk@siac.com&quot;, &quot;Please contact the following employee: &quot; & CallerName & &quot; at : &quot; & Telephone & &quot;, after reviewing the following question: &quot; & RequestedQuestion & &quot; Thank you, &quot; & UserName, &quot; True&quot;
DoCmd.Close acForm, &quot;HelpDeskCalls&quot;, acSaveYes
DoCmd.OpenForm &quot;TicketOption&quot;
End Sub[/tt]

I removed the brackets b/c I was getting &quot;can't find this field error&quot;
 
Remove the quotation marks around the True since SendNotesMail is looking for a boolean and you're sending it a string.

Cheers,

Pete
 
By my reckoning that should about do it! Has it worked JD? ----------------------------------
Ben O'Hara
Home: bpo@RobotParade.co.uk
Work: bo104@westyorkshire.pnn.police.uk
Web: ----------------------------------
 
Guys don't leave me...it's still not working now I am getting a compile error: syntax error: in the module which highlights this line:
Set NotesDb = .GETDATABASE(Mail3/SIAC&quot;, &quot;mail/jperez.nsf&quot;)
 
Ben,

could I zip you my database hopefully you could see what I am not seeing???
 
Ben,

I saw that thread where you posted the code for using Access with Lotus Notes. Could you please see if this makes sense:
[tt]Option Compare Database

Private Declare Function apiFindWindow Lib &quot;user32&quot; Alias _
&quot;FindWindowA&quot; (ByVal strClass As String, _
ByVal lpWindow As String) As Long

Private Declare Function apiSendMessage Lib &quot;user32&quot; Alias _
&quot;SendMessageA&quot; (ByVal Hwnd As Long, ByVal msg As Long, ByVal _
wParam As Long, lParam As Long) As Long

Private Declare Function apiSetForegroundWindow Lib &quot;user32&quot; Alias _
&quot;SetForegroundWindow&quot; (ByVal Hwnd As Long) As Long

Private Declare Function apiShowWindow Lib &quot;user32&quot; Alias _
&quot;ShowWindow&quot; (ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long

Private Declare Function apiIsIconic Lib &quot;user32&quot; Alias _
&quot;IsIconic&quot; (ByVal Hwnd As Long) As Long

Function SendNotesMail(strTo As String, strCC As String, strSubject As String, strBody As String, strFilename As String, ParamArray strFiles())
Dim doc As Object 'Lotus NOtes Document
Dim rtitem As Object '
Dim Body2 As Object
Dim ws As Object 'Lotus Notes Workspace
Dim oSess As Object 'Lotus Notes Session
Dim oDB As Object 'Lotus Notes Database
Dim X As Integer 'Counter
'use on error resume next so that the user never will get an error
'only the dialog &quot;You have new mail&quot; Lotus Notes can stop this macro
If fIsAppRunning = False Then
MsgBox &quot;Lotus Notes is not running&quot; & Chr$(10) & &quot;Make sure Lotus Notes is running and you have logged on.&quot;
Exit Function
End If

On Error Resume Next

Set oSess = CreateObject(&quot;Notes.NotesSession&quot;)
'access the logged on users mailbox
Set oDB = oSess.GETDATABASE(&quot;&quot;, &quot;&quot;)
Call oDB.OPENMAIL

'create a new document as add text
Set doc = oDB.CREATEDOCUMENT
Set rtitem = doc.CREATERICHTEXTITEM(&quot;Body&quot;)
doc.sendto = strTo
doc.Subject = strSubject
doc.Body = strBody & vbCrLf & vbCrLf

'attach files
If strFilename <> &quot;&quot; Then
Set Body2 = rtitem.EMBEDOBJECT(1454, &quot;&quot;, strFilename)
If UBound(strFiles) > -1 Then
For X = 0 To UBound(strFiles)
Set Body2 = rtitem.EMBEDOBJECT(1454, &quot;&quot;, strFiles(X))
Next X
End If
End If
doc.Send False
End Function

Sub test()
Dim strTo As String 'The sendee(s) Needs to be fully qualified address. Other names seperated by commas
Dim strCC As String
Dim strSubject As String 'The subject of the mail. Can be &quot;&quot; if no subject needed
Dim strBody As String 'The main body text of the message. Use &quot;&quot; if no text is to be included.
Dim FirstFile As String 'If you are embedding files then this is the first one. Use &quot;&quot; if no files are to be sent
Dim SecondFile As String 'Add as many extra files as is needed, seperated by commas.
Dim ThirdFile As String 'And so on.

strTo = &quot;Route_To&quot;
strCC = &quot;HRHelpDesk@siac.com&quot;
strSubject = &quot;This ticket has been routed by the HR Help Desk&quot;
strBody = (&quot;Please contact the following employee: &quot; & CallerName & &quot; at : &quot; & Telephone & &quot;, after reviewing the following question: &quot; & RequestedQuestion & &quot; Thank you, &quot; & UserName)
strBody = &quot;&quot;
FirstFile = &quot;&quot;
SecondFile = &quot;&quot;
ThirdFile = &quot;&quot;

SendNotesMail strTo, strCC, strSubject, strBody, FirstFile, SecondFile, ThirdFile
End Sub

Private Function fIsAppRunning() As Boolean
'Looks to see if Lotus Notes is open
'Code adapted from code by Dev Ashish

Dim lngH As Long
Dim lngX As Long, lngTmp As Long
Const WM_USER = 1024
On Local Error GoTo fIsAppRunning_Err
fIsAppRunning = False

lngH = apiFindWindow(&quot;NOTES&quot;, vbNullString)

If lngH <> 0 Then
apiSendMessage lngH, WM_USER + 18, 0, 0
lngX = apiIsIconic(lngH)
If lngX <> 0 Then
lngTmp = apiShowWindow(lngH, 1)
End If
fIsAppRunning = True
End If
fIsAppRunning_Exit:
Exit Function
fIsAppRunning_Err:
fIsAppRunning = False
Resume fIsAppRunning_Exit
End Function[/tt]

[tt]Private Sub Send_Click()
SendNotesMail &quot;This ticket has been routed by the HR Help Desk&quot;, &quot;&quot;, Me.Route_To, &quot;HRHelpDesk@siac.com&quot;, &quot;Please contact the following employee: &quot; & CallerName & &quot; at : &quot; & Telephone & &quot;, after reviewing the following question: &quot; & RequestedQuestion & &quot; Thank you, &quot; & UserName, True
DoCmd.Close acForm, &quot;HelpDeskCalls&quot;, acSaveYes
DoCmd.OpenForm &quot;TicketOption&quot;
End Sub[/tt]

I am not getting a compile error but when I click the Send button. Lotus Notes doesn't launch.it like if it automatically send it to Notes.

 
In your last post where you have a syntax error, you're missing a &quot;
|
Here v
Set NotesDb = .GETDATABASE(Mail3/SIAC&quot;, &quot;mail/jperez.nsf&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top