Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compilation error while calling sub routine 1

Status
Not open for further replies.

JackOTH

Technical User
Aug 8, 2003
7
NL
Hi everybody,

I'm kind a new at this visual basic stuff

Does anybody know why I get a compilation error when I use the following code for a button in my Form:

StuurEmail ("subject","bodytekst","email@email.com","c:\offertetemp\pdf\offerte.pdf",1,True,False)

the error states: Compilation error '=' was expected

the Subroutine is as following:

Public Sub StuurEmail(strEsubject As String, strEbody As String, strSendto As String, strAttach As String, intNoAttach As Integer, booDisplay As Boolean, booSend As Boolean)

Set email = CreateObject("Outlook.Application")
Set Item = email.createitem(0)

With Item
.Subject = esubject
.To = sendto
.Body = ebody


.Attachments.Add (strAttach)

If booDisplay = True Then .Display
If booSend = True Then .send

End With

Set email = Nothing
Set Item = Nothing

End Sub
 
It's a quirk of VBA. Try it without the parentheses:
Code:
StuurEmail "subject","bodytekst","email@email.com","c:\offertetemp\pdf\offerte.pdf",1,True,False
The use of parentheses implies a function with a return value:
Code:
  nResult = MyFunction(Arg1,Arg2,Arg3)
 
try this one.... from exceltip.com, not mine..

hope this will help


a




Sub SendAnEmailWithOutlook()
' creates and sends a new e-mail message with Outlook
Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-mail message
With olMailItem
.Subject = "Subject for the new e-mail message" ' message subject
Set ToContact = .Recipients.Add("name@company.org") ' add a recipient
'Set ToContact = .Recipients.Add("name@company.com") ' add a recipient
ToContact.Type = olCC ' set latest recipient as CC
Set ToContact = .Recipients.Add("name@org.net") ' add a recipient
ToContact.Type = olBCC ' set latest recipient as BCC
.Body = "This is the message text" & Chr(13)
' the message text with a line break
'.Attachments.Add "C:\FolderName\Filename.txt", olByValue, , _
"Attachment" ' insert attachment
' .Attachments.Add "C:\FolderName\Filename.txt", olByReference, , _
"Shortcut to Attachment" ' insert shortcut
' .Attachments.Add "C:\FolderName\Filename.txt", olEmbeddedItem, , _
"Embedded Attachment" ' embedded attachment
' .Attachments.Add "C:\FolderName\Filename.txt", olOLE, , _
"OLE Attachment" ' OLE attachment
.OriginatorDeliveryReportRequested = True ' delivery confirmation
.ReadReceiptRequested = True ' read confirmation
'.Save ' saves the message for later editing
.Send ' sends the e-mail message (puts it in the Outbox)
End With
Set ToContact = Nothing
Set olMailItem = Nothing
Set OLF = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top