By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,510 Members | 1,441 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,510 IT Pros & Developers. It's quick & easy.

VBA: Duplicated code in another form is not working

P: 3
Hello all, I have this interesting problem and it has me scratching my head. I have updated a few forms to use CDOSYS to email instead of using the doCmd.SendObject.
Expand|Select|Wrap|Line Numbers
  1.         Dim objMessage As Object
  2.         Dim strFromEmail As String
  3.         Dim intCaller As Integer
  4.         Dim strCallerComments As String
  5.         Dim strCallerEmail As String
  6.         Dim strCallerPhoneNumber As String
  7.         Dim strHTMLBody As String
  8.         Dim strDateOfCall As String
  9.         Dim strCallerName As String
  10.         Dim strAssignedTo As String
  11.  
  12.         strFromEmail = DLookup("[E-Mail Address]", "[CSD Personnel]", "[CSD Name] = '" & txtCallLogBy.Value & "'")
  13.         strAssignedTo = DLookup("[CSD Name]", "[CSD Personnel]", "[Initials] = '" & Initials.Value & "'")
  14.         intCaller = UserID.Value
  15.         strCallerName = DLookup("[UserName]", "[Users2]", "[UserID] = " & intCaller)
  16.         strCallerComments = CallerComments.Value
  17.         strCallerEmail = DLookup("[E-MailAddress]", "[Users2]", "[UserName] = '" & strCallerName & "'")
  18.         strCallerPhoneNumber = DLookup("[PhoneNumber]", "[Users2]", "[UserName] = '" & strCallerName & "'")
  19.         strDateOfCall = CallDateTime.Value
  20.  
  21.         strHTMLBody = "<h1>Call Log Email</h1><br><br>" & stSubject & "<br><br>"
  22.         strHTMLBody = strHTMLBody & "<b>Assigned To:</b> " & strAssignedTo & "<br><br>"
  23.         strHTMLBody = strHTMLBody & "<br><br><b>Caller's Name:</b> " & strCallerName & "<br><br>"
  24.         strHTMLBody = strHTMLBody & "<b>Caller's Email:</b> " & strCallerEmail & "<br><br>"
  25.         strHTMLBody = strHTMLBody & "<b>Caller's Phone Number:</b> " & Format(strCallerPhoneNumber, "(###) ###-####") & "<br><br>"
  26.         strHTMLBody = strHTMLBody & "<b>Reason For Calling:</b> " & strCallerComments & "<br><br>"
  27.         strHTMLBody = strHTMLBody & "<b>Date Of Call:</b> " & strDateOfCall
  28.  
  29.         Set objMessage = CreateObject("CDO.Message")
  30.             objMessage.Subject = stSubject
  31.             objMessage.From = strFromEmail
  32.             objMessage.To = stSendTo
  33.             objMessage.HTMLBody = strHTMLBody
  34.             objMessage.Configuration.Fields.Item _
  35.             ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  36.  
  37.             'Name or IP of Remote SMTP Server
  38.             objMessage.Configuration.Fields.Item _
  39.             ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.truecos.com"
  40.  
  41.             'Server port (typically 25)
  42.             objMessage.Configuration.Fields.Item _
  43.             ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  44.             objMessage.Configuration.Fields.Update
  45.             objMessage.sEnd
  46.  
This is the code that in 3 of 4 forms is working correctly. On the form that isn't sending, I have stepped through the entire procedure, and set a watch on objMessage. Once I pass send, the object correctly has a sent date, but no email comes!

I am using Access 2003, XP Pro.
Does anyone have any thoughts or ideas?
Thanks,
squiggly12
Mar 14 '08 #1
Share this Question
Share on Google+
2 Replies


FishVal
Expert 2.5K+
P: 2,653
Hi, there.

From the code you've posted it is not obvious whether objMessage.To property is being set correctly. Anyway, if the code doesn't raise an error, then, I guess, it means that email was sent but wasn't delivered by mail server.

Regards,
Fish.
Mar 17 '08 #2

P: 3
Hi, there.

From the code you've posted it is not obvious whether objMessage.To property is being set correctly. Anyway, if the code doesn't raise an error, then, I guess, it means that email was sent but wasn't delivered by mail server.

Regards,
Fish.
Fish,
Thank you for the reply. I have checked all of the variables and they are being set correctly, and the sent date within the objMessage object is happening. I will have our network admin check the mail server to see if there are mails being stopped. The thing that is bothering me is that on 3 other forms, the same exact code is being used and emails are generated and sent.

Thanks again!
Mar 17 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.