Solved

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

Posted on 2003-11-14
10
1,810 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 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

22 Experts available now in Live!

Get 1:1 Help Now