• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1843
  • Last Modified:

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

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
YZlat
Asked:
YZlat
  • 4
  • 3
  • 2
1 Solution
 
Arthur_WoodCommented:
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
 
Arthur_WoodCommented:
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
 
YZlatAuthor Commented:
so what do I put instead of objSendMail.SMTPHost ?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Arthur_WoodCommented:
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
 
Arthur_WoodCommented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
Better use the free vbSendMail component: http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
YZlatAuthor Commented:
emoreau, that's exactly what I have
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>emoreau, that's exactly what I have


??? your code at the top is showing CDONTS! I am talking about vbSendMail!
0
 
YZlatAuthor Commented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now