Solved

Compilation Error Problem

Posted on 2007-12-06
5
149 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 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

12 Experts available now in Live!

Get 1:1 Help Now