Solved

Compilation Error Problem

Posted on 2007-12-06
5
153 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…

756 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