Solved

Compilation Error Problem

Posted on 2007-12-06
5
152 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

856 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