Compile error: Expected: end of statement

SoxPats83

Registered User.
Local time
Today, 00:43
Joined
May 7, 2010
Messages
196
hi all. i am getting an error in my coding that i suspect may have a sinple resolution. the purpose of my form is to send emails and i have the To: and Cc: lines are predetermined. the problem that i am running into is in my subject line. below is a sample of my coding...
Code:
Private Sub Command20_Click()
        Dim mess_body As String
        Dim appOutLook As Outlook.Application
        Dim MailOutLook As Outlook.MailItem
        Dim MYDate
        Dim test1
        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)
 
            MYDate = Date
            test1 = tes
            Set appOutLook = CreateObject("Outlook.Application")
            Set MailOutLook = appOutLook.CreateItem(olMailItem)
            With MailOutLook
            .BodyFormat = olFormatRichText
            .To = [EMAIL="test@test.com"]test@test.com[/EMAIL]
            .CC = "[EMAIL="test1@test1.com"]test1@test1.com[/EMAIL]"
            .Subject = MYDate test
            .HTMLBody = Me.Mess_Text
            If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
                .Attachments.Add (Me.Mail_Attachment_Path)
            End If
            '.DeleteAfterSubmit = True   'This would let Outlook send th note without storing it in your sent bin
            .Send
            End With
            'MsgBox MailOutLook.Body
            Exit Sub
email_error:
            MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
            Resume Error_out
Error_out:
End Sub
the problem i am sure is within the .subject line. any help would be appreciated.

Thanks!
 
Yes, that would be a problem. You have a space.

.Subject = MYDate test

You can't have it like that but you can have

.Subject = MYDate & "test"

Same with this:
test1 = tes
 
Yes, that would be a problem. You have a space.

.Subject = MYDate test

You can't have it like that but you can have

.Subject = MYDate & "test"

Same with this:
test1 = tes
thank you very much. that did the trick. now i am running into another problem. no error being given this time... but i would like to have a space between these two. the end result being: "5/25/10 test" rather than: "5/25/10test"
 
Change to

.Subject = MYDate & " test"
as always you saved me from another problem i was having. i have yet another thing i would like too accomplish on this... on my form i have a text box, and between MyDate and test, i would like to have the values of this text box displayed serated by commas (the values in the text box are inputted based on selections made from a listbox. let's call this text box txt1.
 
alright, now i am getting a compile error in regars to the
Code:
Dim appOutLook As Outlook.Application
line.
 
could the problem be that i am using Access 2003 and my default Outlook is 2007?
 
Well, apart from the errors in coding, perhaps.

But you should maybe look into using LATE binding instead of EARLY binding (using code like:

Dim appOutLook As Object

Set appOutlook = CreateObject("Outlook.Application")

Which then can keep you from reference errors.
 

Users who are viewing this thread

Back
Top Bottom