Solved

Run-time error '438' Object does not support this property or method

Posted on 2003-11-14
10
1,809 Views
Last Modified: 2008-02-26
I have a DLL that gives me the following error: Run-time error '438' Object does not support this property or method.
here is my code:

Public Function SendEmail(vServer As Variant, vFrom As Variant, vFromName As Variant, vTo As Variant, vToName As Variant, vSubject, vFileName, vMsgBody)
    On Error GoTo errHandler
   
    'a reference to microsoft cdo for nts 1.2 library
    Dim objSendMail As CDONTS.NewMail
    Set objSendMail = New CDONTS.NewMail
    objSendMail.SMTPHost = vServer           <-----ERROR HERE
    objSendMail.From = vFrom
    objSendMail.FromDisplayName = vFromName
    objSendMail.Recipient = vTo
    objSendMail.RecipientDisplayName = vToName
    objSendMail.ReplyToAddress = vFrom
    objSendMail.Subject = vSubject
    objSendMail.Attachment = vFileName 'attached file name
    objSendMail.Message = vMsgBody
    objSendMail.Send
    Set objSendMail = Nothing
    SendEmail = 1
    Exit Function
errHandler:
    SendEmail = 0

End Function
0
Comment
Question by:YZlat
  • 4
  • 3
  • 2
10 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9748462
there is no .SMTPHost method or property on the CDONTS.NewMail object

in addition, most of the Properties that you appear to be using, are NOT valid on a CDONTS.NewMail object.

where did you get this code?

AW
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9748493
If you tried to do a Run with Full Compile, this code would NOT compile.  The error you are getting is because you are relying on the Just-In-Time compiler, to compile the code, JUST before it is needed.

0
 
LVL 35

Author Comment

by:YZlat
ID: 9749205
so what do I put instead of objSendMail.SMTPHost ?
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9749609
you need to use the Object model that is appropriate to the task you are trying to accomplish.  You cannot simply grab an clkass without knowing what it is intended to do.  What are you trying to accomplish, and why did you think the CDONTS.NewMail class was the right one to use?

If you are using the CDONTS.NewMail class, then look at the methods and properties that THAT class supports, and use those.

AW
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9750082
do you have .NET?  

here is a code snippet that uses VB.NET:

        Dim m As New System.Web.Mail.MailMessage()
     
        m.From = "YOU@YOURSITE.com"
        m.To = "HIM@somwhere.com"
        m.Body = txtEmailBody.Text
        m.Subject = cboEmailTrackingNumber.Text

        Try
            System.Web.Mail.SmtpMail.SmtpServer = "mail.YOURSITE.com"
            System.Web.Mail.SmtpMail.Send(m)
        Catch ex As Exception
            Success = False
            Err = ex.Message
        End Try

AW
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 9750995
Better use the free vbSendMail component: http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
LVL 35

Author Comment

by:YZlat
ID: 9857776
emoreau, that's exactly what I have
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 9858549
>>emoreau, that's exactly what I have


??? your code at the top is showing CDONTS! I am talking about vbSendMail!
0
 
LVL 35

Accepted Solution

by:
YZlat earned 0 total points
ID: 9930920
could not get the old code to work so I changed it to send mail through MS Outlook.
Here is my solution:

Public Function SendEmail(vServer As Variant, vFrom As Variant, vFromName As Variant, vTo As Variant, vToName As Variant, vSubject, vFileName, vMsgBody)
    On Error GoTo errHandler
    Dim objAtt As Object
    'reference to MS Outlook 9.0 Object Library
    Dim objOutlook As New Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
 
    'Create a message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    objOutlookMsg.Display
    With objOutlookMsg
        .To = vTo
        .Subject = vSubject
        .Body = vMsgBody
        ' .Importance = olImportanceHigh
        .Attachments.Add (vFileName)
        .Send
    End With
   
    Set objOutlook = Nothing
   
    SendEmail = 1
    Exit Function
errHandler:
    SendEmail = 0

End Function
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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.
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…
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…

746 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