VBA: Duplicated code in another form is not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • squiggly12
    New Member
    • Mar 2008
    • 3

    VBA: Duplicated code in another form is not working

    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.SendObjec t.
    Code:
            Dim objMessage As Object
            Dim strFromEmail As String
            Dim intCaller As Integer
            Dim strCallerComments As String
            Dim strCallerEmail As String
            Dim strCallerPhoneNumber As String
            Dim strHTMLBody As String
            Dim strDateOfCall As String
            Dim strCallerName As String
            Dim strAssignedTo As String
            
            strFromEmail = DLookup("[E-Mail Address]", "[CSD Personnel]", "[CSD Name] = '" & txtCallLogBy.Value & "'")
            strAssignedTo = DLookup("[CSD Name]", "[CSD Personnel]", "[Initials] = '" & Initials.Value & "'")
            intCaller = UserID.Value
            strCallerName = DLookup("[UserName]", "[Users2]", "[UserID] = " & intCaller)
            strCallerComments = CallerComments.Value
            strCallerEmail = DLookup("[E-MailAddress]", "[Users2]", "[UserName] = '" & strCallerName & "'")
            strCallerPhoneNumber = DLookup("[PhoneNumber]", "[Users2]", "[UserName] = '" & strCallerName & "'")
            strDateOfCall = CallDateTime.Value
                    
            strHTMLBody = "<h1>Call Log Email</h1><br><br>" & stSubject & "<br><br>"
            strHTMLBody = strHTMLBody & "<b>Assigned To:</b> " & strAssignedTo & "<br><br>"
            strHTMLBody = strHTMLBody & "<br><br><b>Caller's Name:</b> " & strCallerName & "<br><br>"
            strHTMLBody = strHTMLBody & "<b>Caller's Email:</b> " & strCallerEmail & "<br><br>"
            strHTMLBody = strHTMLBody & "<b>Caller's Phone Number:</b> " & Format(strCallerPhoneNumber, "(###) ###-####") & "<br><br>"
            strHTMLBody = strHTMLBody & "<b>Reason For Calling:</b> " & strCallerComments & "<br><br>"
            strHTMLBody = strHTMLBody & "<b>Date Of Call:</b> " & strDateOfCall
            
            Set objMessage = CreateObject("CDO.Message")
                objMessage.Subject = stSubject
                objMessage.From = strFromEmail
                objMessage.To = stSendTo
                objMessage.HTMLBody = strHTMLBody
                objMessage.Configuration.Fields.Item _
                ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
                
                'Name or IP of Remote SMTP Server
                objMessage.Configuration.Fields.Item _
                ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.truecos.com"
                
                'Server port (typically 25)
                objMessage.Configuration.Fields.Item _
                ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
                objMessage.Configuration.Fields.Update
                objMessage.sEnd
    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
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    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.

    Comment

    • squiggly12
      New Member
      • Mar 2008
      • 3

      #3
      Originally posted by FishVal
      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!

      Comment

      Working...