?
Solved

424 Object Required

Posted on 2004-03-30
32
Medium Priority
?
1,076 Views
Last Modified: 2008-02-20
I access the following code using a button on a form in Visual Studio, on running and selecting the button I get the following error message 'Runtime error 424: Object required', has anyone any clues as to what the problem maybe ??????

Private Sub Command1_Click()
Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody

sTo = "intendedrecipient@msn.com"
sFrom = "intendedrecipient@msn.com"
sSubject = "Insert here your subject text"
sTextBody = "Insert here your plain body text"

Dim objMail
'Create the mail object
Set objMail = Server.CreateObject("CDO.Message")

'Set key properties
objMail.From = sFrom
objMail.To = sTo
objMail.Subject = sSubject
objMail.TextBody = sTextBody

'Send the email
objMail.Send

'Clean-up mail object
Set objMail = Nothing

End Sub
0
Comment
Question by:leebee300
[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
  • 15
  • 5
  • 5
  • +1
32 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 10712522
When do you get the error ? At which line ?

An alternative to send email: a free vb dll:
www.freevbcode.com/ShowCode.Asp?ID=109
0
 

Author Comment

by:leebee300
ID: 10712548
Hi Dhaest,

I get the error at the following line.......

Set objMail = Server.CreateObject("CDO.Message")
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 10712572
Try it with replacing
Set objMail = Server.CreateObject("CDO.Message")
to
Set objMail = CreateObject("CDONTS.NewMail")
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!

 

Author Comment

by:leebee300
ID: 10712592
Dhaest,

its CDONTS I am trying to move away from as Microsoft is phasing in CDOSYS as a more powerful mail facility for future operating systems
0
 

Author Comment

by:leebee300
ID: 10712600
sorry forgot to add, that CDONTS is not supported with service packs to 2000 and XP
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10712816
Maybe stupid question, but did you add a reference to the CDO?
0
 

Author Comment

by:leebee300
ID: 10712843
please tell me that I have made as stupid mistake, what is the reference ??
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 10712868
Reference to Microsoft CDO for Windows 2000 Library
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10712871
Normally when you want to use Word or Excel or something else, you add a reference to that dll or exe through the
menu Project-->References
0
 

Author Comment

by:leebee300
ID: 10712888
I have done this then tried to F5 but still the same error messages is displayed
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10712906
Look at:

http://www.paulsadowski.com/WSH/cdo.htm

And at least remove the Server. before the createObject!!
0
 

Author Comment

by:leebee300
ID: 10712965
what do you mean remove the server ??, I am not a VB`er so bare with me, I want to check it works then adapt it in to some C# code
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 10713014
Set objMail = CreateObject("CDO.Message")
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10713043
I meant remove 'Server.' from server.createobject, in VB you do not use Sever.
Furthermore your code looks good:

--------------------------

Private Sub Command1_Click()
Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody

sTo = "intendedrecipient@msn.com"
sFrom = "intendedrecipient@msn.com"
sSubject = "Insert here your subject text"
sTextBody = "Insert here your plain body text"

Dim objMail
'Create the mail object
Set objMail = CreateObject("CDO.Message")   'This line do not use Server.

'Set key properties
objMail.From = sFrom
objMail.To = sTo
objMail.Subject = sSubject
objMail.TextBody = sTextBody

'Send the email
objMail.Send

'Clean-up mail object
Set objMail = Nothing

End Sub
0
 

Author Comment

by:leebee300
ID: 10713083
stressing now, did that, thankfully got no compiler error but got nothing else either after pressing the button on the form after F5'ing, I entered perfectly valid email addresses in the....

sTo = "intendedrecipient@msn.com"
sFrom = "intendedrecipient@msn.com"

.......quotes
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 10713118
http://www.paulsadowski.com/WSH/cdo.htm

Do you use a remote or local server ?
0
 

Author Comment

by:leebee300
ID: 10713131
local
0
 

Author Comment

by:leebee300
ID: 10713242
sorry that it is only worth 30 points, its all`s I had left
0
 

Author Comment

by:leebee300
ID: 10713973
would using a local server affect the code used ??
0
 
LVL 1

Expert Comment

by:dreffed
ID: 10714478
What mail server are you sending it through....

Your code does not mention it...

Read this aritcle....
http://www.developerfusion.com/show/1772/


Dreffed
0
 

Author Comment

by:leebee300
ID: 10714538
where would my code mention it please dreffed ??

the article you sent my way has unfortunately confused me even further
0
 
LVL 1

Expert Comment

by:dreffed
ID: 10714683
Sorry about that....

I have to go ...I'll get back shortly...with your soluton.

sorry !?! :)
0
 

Author Comment

by:leebee300
ID: 10714712
thanks very much for your help dreffed, hope to hear from you soon.
0
 
LVL 1

Expert Comment

by:dreffed
ID: 10715293
I have just done some testing with the CDO.Message object, so scrub my last comment about the mail server.  It seems that CDO will connect using your MAPI client.
Check that you have the necessary libraries...

Under visual studio....
go project -> references

scroll through the list and look for
Microsoft CDO ....

Do you have these?

change the line...
dim objMail

to
dim objMail as object

it is always best to be explicit with variables...

I found this site useful and detailed...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/exchanchor/htms/msexchsvr_cdo121.asp


I hope this more helpful..

Dreffed
0
 

Author Comment

by:leebee300
ID: 10721947
did the testing you did work ok ??

I am still having no luck, do you have to add a route to the server at some point in the code, like when you are connecting to an SQL database using C# for example
0
 
LVL 1

Accepted Solution

by:
dreffed earned 120 total points
ID: 10724764
I added the following code to one of my programs, and it ran...
Please check your code against the following, if it similar, then look for CDO.Message in your registry.
start->run->regedit
menu->find
"CDO.Message"

If it is missing then that is your problem.

The code I used to test :)
on a new form....

' ***************************
Option Explicit
' add 3 labels
'       lblTo
'       lblSubject
'       lblMessage
' add 3 test boxes
'       txtTo       multiline = false
'       txtSubject  multiline = false
'       txtMessage  multiline = true
' add 2 buttons
'       btnSend
'       btnCancel

' uses CDO.Message to send an email
Private Const SENDER = "your.email@some.server.com"

Private Sub btnCancel_Click()
    Unload Me
End Sub

Private Sub btnSend_Click()
    ' check the values
    If Len(Me.txtSubject.Text) = 0 Or _
        Len(Me.txtTo.Text) = 0 Then
       
        ' need a subject and to address
       
        MsgBox "Please provide an email address to send to and a subject."
        Exit Sub
    End If
   
    ' set up the error handler
    On Error GoTo errorhandler
    Dim objMail As Object

    ' declare and populate the object
    Set objMail = CreateObject("CDO.Message")
   
    Debug.Print "CDO.Message: Created"
   
    'Set key properties
    objMail.From = SENDER
    objMail.To = Me.txtTo.Text
    objMail.Subject = Me.txtSubject.Text
    objMail.TextBody = Me.txtMessage.Text
   
    Debug.Print "CDO.Message: Populated"
   
    'Send the email
    objMail.Send
   
    Debug.Print "CDO.Message: Sent"
   
    'Clean-up mail object
    Set objMail = Nothing
   
    Debug.Print "CDO.Message: Nothing"

    MsgBox "Mail Sent"
   
    Exit Sub

    ' handle any errors
errorhandler:
    MsgBox "Error:" + vbCrLf + _
            CStr(Err.Number) + vbTab + Err.Description
    Set objMail = Nothing

End Sub
' *****************************************

0
 

Author Comment

by:leebee300
ID: 10724884
I have moved across to C# to further develop this problem, I have finally got rid of my previous error, and I now get an error saying that the The server response was: 550 5.7.1 Unable to relay for anaddress@ontheweb.com, any ideas, sorry to waste your time if you dont use C#, I had to start using C# becasue this is the language I develop in
0
 
LVL 1

Expert Comment

by:dreffed
ID: 10724948
C# is ok and on my list of languages....

...
That is a better message, the mailer is working, but the mailserver you are sending your mail through will not allow you to send to external email addresses.

this site has been v.helpful, and now you are in C# the code will help.
http://www.systemwebmail.com/faq/4.3.10.aspx

I find when this happens talk to the IT bod who deals with the mailserver and find out whether you can relay or whether they can allow your machine to bypass the check.

I have always used Mabry SMPTX to mail, but after your thread I am begining to like CDO.Message.

Thanks for the new idea.

Dreffed
0
 

Author Comment

by:leebee300
ID: 10724973
no thankyou for the help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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