Solved

Compilation Error Problem

Posted on 2007-12-06
5
150 Views
Last Modified: 2010-04-30
I am running the script below, to send an email using CDO, but keep getting a compilation error.

Can anybody help, Thanks

Set objEmail = CreateObject("CDO.Message")    
objEmail.Configuration.Fields.Item( & _     "http://schemas.microsoft.com/cdo/configuration/sendusing") = 2    
objEmail.Configuration.Fields.Item( & _     "http://schemas.microsoft.com/cdo/configuration/smtpserver") = &_ "smtp.servername"    
objEmail.Configuration.Fields.Item( & _     "http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25    
objEmail.Configuration.Fields.Update    
objEmail.From = "example.com"    
objEmail.To = "example1.com"    
objEmail.Subject = "Test Message"    
objEmail.Textbody = "This is a test message."    
objEmail.Send    
Set objEmail = nothing  
0
Comment
Question by:halifaxman
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 20418316
What and where is the error?
0
 
LVL 17

Accepted Solution

by:
wobbled earned 500 total points
ID: 20418319
It is because you are using the &_ at the start.  

Set objEmail = CreateObject("CDO.Message")
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.servername"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.From = "example.com"
objEmail.To = "example1.com"
objEmail.Subject = "Test Message"
objEmail.Textbody = "This is a test message."
objEmail.Send
Set objEmail = Nothing
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 20418334
That's a syntax error, do you think that's what he meant?
0
 
LVL 17

Expert Comment

by:wobbled
ID: 20419384
I think so.  It just won't allow you to put the ampersand underscore before the text string
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 20426961
Yes. I thought he had just compressed it on to one line for us to see the code more easily, so I corrected it before testing. Doh!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now