Email Body Coding

G

Guest

I'm using a code (below) to email someone which should be fine, but I'd like
to enter the following the body of the email.

Dear Someone *
*
Please find attached etc etc etc*
*
Thanks

I just don't know how to code the returns at the end of the sentence into VB
(where I've put *). Any help appreciated.

Thanks

Private Sub cmdEmailLynx_Click()

Me.NotificationDate = Now()
Me.AdminName.SetFocus
Me.AdminPosition.SetFocus
Me.AdminPhone.SetFocus
Me.AdminEmail.SetFocus

Dim strWhere As String
strWhere = "[CRDNumber] = " & Me.[CRDNumber]

If Me.Dirty Then
Me.Dirty = False
End If

If Me.NewRecord Then
MsgBox "Enter all information required!", vbExclamation
Else
DoCmd.OpenReport "rptLynxRequest", acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, "rptLynxRequest", acFormatSNP,
strSavedClaim

Dim strSavedClaim As String
strSavedClaim = "C:\Temp\" & "rptLynxRequest" & ".snp"

Dim Olk As Object, OlkMsg As Object
Set Olk = CreateObject("Outlook.Application")
Set OlkMsg = Olk.CreateItem(0)

With OlkMsg
.To = "(e-mail address removed)"
.Subject = "Claim " & Me![ConsignmentNumber]
.Body = "Dear Jonathan"
.Attachments.Add ("C:\Temp\rptLynxRequest.snp")
.Display
End With

Set Olk = Nothing
Set OlkMsg = Nothing
End If

End Sub
 
S

SusanV

vbCrLf will put the following text at the beginning of the next line. For
example:

srtText = "The first line" & vbCrLf & "The second line" and vbCrLf & vbCrLf
& "Skipped a line"

will return:

The first line
The second line

Skipped a line
 
B

BruceM

Beyond the specific question that has already been answered, I have a few
questions/observations.
1) I don't see the point to setting the focus to a series of controls after
setting the notification date to Now()
2) After you explicitly save the record, it will not be a new record any
more. The If Me.NewRecord message box will not appear, so there is no point
to having it.
3) You will need to define strSavedClaim before the line of code in which
you use it
4) The user's Temp file may eventually end up with a lot of files. I
believe there is a way of using VBA to delete such files after you are
through with them, but I don't know the details. I'm pretty sure a
newsgroup search would turn up some solutions.
 
G

Guest

Excellento!! Thanks very much!

SusanV said:
vbCrLf will put the following text at the beginning of the next line. For
example:

srtText = "The first line" & vbCrLf & "The second line" and vbCrLf & vbCrLf
& "Skipped a line"

will return:

The first line
The second line

Skipped a line



--
hth,
SusanV


albycindy said:
I'm using a code (below) to email someone which should be fine, but I'd
like
to enter the following the body of the email.

Dear Someone *
*
Please find attached etc etc etc*
*
Thanks

I just don't know how to code the returns at the end of the sentence into
VB
(where I've put *). Any help appreciated.

Thanks

Private Sub cmdEmailLynx_Click()

Me.NotificationDate = Now()
Me.AdminName.SetFocus
Me.AdminPosition.SetFocus
Me.AdminPhone.SetFocus
Me.AdminEmail.SetFocus

Dim strWhere As String
strWhere = "[CRDNumber] = " & Me.[CRDNumber]

If Me.Dirty Then
Me.Dirty = False
End If

If Me.NewRecord Then
MsgBox "Enter all information required!", vbExclamation
Else
DoCmd.OpenReport "rptLynxRequest", acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, "rptLynxRequest", acFormatSNP,
strSavedClaim

Dim strSavedClaim As String
strSavedClaim = "C:\Temp\" & "rptLynxRequest" & ".snp"

Dim Olk As Object, OlkMsg As Object
Set Olk = CreateObject("Outlook.Application")
Set OlkMsg = Olk.CreateItem(0)

With OlkMsg
.To = "(e-mail address removed)"
.Subject = "Claim " & Me![ConsignmentNumber]
.Body = "Dear Jonathan"
.Attachments.Add ("C:\Temp\rptLynxRequest.snp")
.Display
End With

Set Olk = Nothing
Set OlkMsg = Nothing
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top