Solved

Compilation Error Problem

Posted on 2007-12-06
5
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

734 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