Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quiz - CDONTS in VB 2

Status
Not open for further replies.

Deadline

Programmer
Feb 28, 2001
367
US
Hi,

I have a piece of code that'll send email using an instance of CDONTS component, which I create using
Code:
CreateObject("CDONTS.NewMail")

My program actually creates an instance of CDONTS inside a
Code:
DO UNTIL
loop; each time after the message has been sent, I try to set that instance to Nothing and the process continues so on..

When I made this to an Exe and tried to run it in the NT Server, I got an error like
Code:
Operation cannot be performed if the object is closed.

Is this error related to CreateObject ??

Very desperate, please F1.

Thank you in advance.


RR.

Keywords
CreateObject
CDONTS
MAPI
NewMail
Nothing



 
Can you post the code of the loop? Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Here we go... partial code

Code:
Call CreateConnection
strSQL = " SELECT DISTINCT empId,tripnumber,ctrycode "
strSQL = strSQL & " FROM clearance "
strSQL = strSQL & " WHERE IsNull(emailedtimestamp) ORDER BY ctrycode"
        
rs.Open strSQL, cn
Do Until rs.EOF
     
lTripNumber = rs.Fields("TripNumber").Value
lEmpId = rs.Fields("empID").Value

strSQL = "SELECT phaseI,phaseII,phaseIII,phaseIV,phaseV, clearby,ctrycode "
strSQL = strSQL & " FROM advisory "
strSQL = strSQL & " WHERE ctrycode ='" & rs.Fields ("ctrycode") & "' AND "
strSQL = strSQL & " (phaseI ='Y' OR "
strSQL = strSQL & " phaseII ='Y' OR "
strSQL = strSQL & " phaseIII='Y' OR "
strSQL = strSQL & " phaseIV ='Y' OR "
strSQL = strSQL & " phaseV  ='Y' )"

rsPhaseInfo.Open strSQL, cn
Do Until rsPhaseInfo.EOF
 strMailText = strMailText & rsPhaseInfo.Fields("clearby") & vbCrLf
 rsPhaseInfo.MoveNext
Loop
rsPhaseInfo.Close
If strMailText <> &quot;&quot; Then
Set cdoMail = CreateObject(&quot;CDONTS.NewMail&quot;)            
With cdoMail
'.To = The actual email' Instead I am using Test email.
  .To = &quot;helpmeplease@urgent.com&quot;
  .From = &quot;AutoEmail&quot;
  .subject = strMailSubject & &quot;Employee ID-&quot; & rs.Fields(&quot;empId&quot;)
  .body = strMailText & vbCrLf & GetEmail(CStr(lEmpId)) & vbCr & rsPhaseInfo.Fields(&quot;ctrycode&quot;)
  .Send
End With
Set cdoMail = Nothing
strSQL = &quot;UPDATE clearance SET EmailedTimeStamp='&quot; & CDate(Now())
strSQL = strSQL & &quot;' WHERE tripNumber=&quot; & lTripNumber & &quot; AND &quot;
strSQL = strSQL & &quot; EmpID=&quot; & lEmpID
strSQL = strSQL & &quot; AND ctrycode='&quot; & rs.Fields(&quot;ctrycode&quot;) & &quot;'&quot;
cn.Execute strSQL
End If
strMailText = &quot;&quot;
        rs.MoveNext
    Loop
    End
ERRORHANDLER:
    MsgBox &quot;Error Number:&quot; & Err.Number & vbCrLf & Err.Description, _
 vbOKOnly, App.Path & App.EXEName
    End
End Sub
 
if the Error is active then Click on Debug then with the menu (VIEW) Click on Call Stack and you see the problems Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
just a guess here, but you are setting the object to nothing immeadiately after the you call the .send method. It could be that the object is getting destroyed before it has a chance to connect to the server and send the mail.
Try insering a message box after the .send call but before the set = Nothing. Let the message box sit for a couple seconds, then click ok to continue on. If that gets rid of the error you may need to delay a few seconds before closing the object. Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top