Email Code correction (1 Viewer)

hootie318

Registered User.
Local time
Today, 14:48
Joined
Oct 28, 2003
Messages
130
I am sending an email from a form and it almost works the way I want it to. I need to accomplish two more things. Here is an example of what the subject needs to be: 2:00 Report Wednesday March 15th, 2006 I cant get the values into the subject line at all.

I can get the info into the body, but I cant get the date to format as the long date, it only shows as 03/15/2006.

Here is my code, can enyone tell me what I am doing wrong?

Private Sub Command4_Click()
On Error Resume Next
Dim daSubject As String
Dim daBody As String
daSubject = ""
daSubject = daSubject & " " & Time.Value & vbCrLf
daSubject = daSubject & " " & Forms!DispatchDay!Date.Value & vbCrLf
daBody = ""
daBody = daBody & " " & Forms!DispatchDay!Date.Value & vbCrLf
daBody = daBody & " " & Time.Value & vbCrLf
daBody = daBody & " " & Notes.Value & vbCrLf

DoCmd.SendObject acSendNoObject, , , "Email1", "Email 2", , "Report", daBody
End Sub
 

hootie318

Registered User.
Local time
Today, 14:48
Joined
Oct 28, 2003
Messages
130
I almost have it. The Subject reads Report: 9:00 A.M. but I cant get the date to show after that. Please help.

Private Sub Command4_Click()
On Error Resume Next
Dim daSubject As String
Dim daBody As String
daSubject = ""
daSubject = daSubject & Time.Value & vbCrLf & "Report" & Forms!DispatchDay!Date.Value & vbCrLf
daBody = ""
daBody = daBody & " " & Forms!DispatchDay!Date.Value & vbCrLf
daBody = daBody & " " & Notes.Value & vbCrLf

DoCmd.SendObject acSendNoObject, , , "Email 1", "Email 2", , "Report: " & Time.Value & vbCrLf & SubformDate.Value & vbCrLf, daBody
End Sub
 

reclusivemonkey

Registered User.
Local time
Today, 14:48
Joined
Oct 5, 2004
Messages
749
Remove the vbCrlLf; you can't use a line field in a Subject line AFAIK.
 

hootie318

Registered User.
Local time
Today, 14:48
Joined
Oct 28, 2003
Messages
130
That worked, thanks. Is there any way to format the date to long date instead of 00/00/0000. I have the field set as long date, but it does not show up that way.
 

reclusivemonkey

Registered User.
Local time
Today, 14:48
Joined
Oct 5, 2004
Messages
749
OK firstly you should sort out a couple of other things. You should never use "Date" as a field name, which it looks as if you have in here; Forms!DispatchDay!Date.Value

Also, remove daSubject = "" and the same line in daBody, they serve no useful purpose. Then, to get a long formatted date, use;

Code:
daSubjectDate = Format(Forms!DispatchDay![i][b]DateFieldName[/b][/i],"Long Date")
daSubject = "Report: " & Time.Value & " " & daSubjectDate

Then use daSubject in your DoCmd.SendObject line. In your example you are setting the subject again rather than using your variable.
 
Last edited:

Users who are viewing this thread

Top Bottom