Solved

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

Posted on 2003-11-14
10
1,823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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
 
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 70

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 70

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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

734 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