Results 1 to 6 of 6
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Get rid of error 251 and add a field in the subject line

    All, I have adapted code gotten off the net to my needs. I am NOT a programmer extraordinaire. What I would like to do is:

    A. Get rid of Error 2501 The SendObject was canceled.

    I tried: MsgBox Err.Number & " " & (Err.Description<>2501) but run into a Runtime error '13".

    B. Add the field CR_Number in the subject line of the message.

    I tried strSubject = "GO Change Request Number " & rstChange_Request("CR_Numbers"), I get Error 3265 Item not found in this collection

    Private Sub Cmd_Email_GO_CRs_Click()
    On Error GoTo Error
    Dim db As Database
    Dim rstChange_Request As Recordset
    Dim strSQL As String
    Dim strSubject, strBody, strAddresses As String
    Set db = CurrentDb()
    strSQL = "SELECT * FROM GO_EMail"
    Set rstChange_Request = db.OpenRecordset(strSQL, dbOpenDynaset)
    If Not rstChange_Request.EOF Then
    strBody = "Action Officers," & vbCrLf & "This is a following on from today's ERB discussion on CR "
    strBody = strBody & rstChange_Request("CR_Numbers") & ". If needed, please back-brief your O6 for SA, and let me know if there is any issues or concerns. Please provide your votes to me NLT 1940 today or this will be approved automatically. Also, feel free to give me a call if you have any questions or issues." & vbCrLf & vbCrLf & vbCrLf
    strBody = strBody & "Date Issue Identified: " & Chr(9) & Chr(9) & Chr(9) & rstChange_Request("Dates") & vbCrLf
    strBody = strBody & "CR Number: " rstChange_Request("CR_Numbers") & vbCrLf
    strBody = strBody & "Change Requested: " & Chr(9) & rstChange_Request("Change Requested") & vbCrLf & vbCrLf
    strBody = strBody & "Unit & Section: " & Chr(9) & Chr(9) & Chr(9) & rstChange_Request("Units") & vbCrLf
    strBody = strBody & "MTOE Para & Bumper Number: " & Chr(9) & rstChange_Request("MTOE Paras") & vbCrLf & vbCrLf


    strBody = strBody & "Rationale: " & Chr(9) & rstChange_Request("Rationale") & vbCrLf & vbCrLf & vbCrLf
    strBody = strBody & "Notes: " & Chr(9) & rstChange_Request("Notes") & vbCrLf
    strBody = strBody & "Action Items: " & Chr(9) & rstChange_Request("Action_Items") & vbCrLf
    rstChange_Request.MoveFirst
    Do While Not rstChange_Request.EOF
    rstChange_Request.MoveNext
    Loop
    End If
    strSubject = "GO Change Request Number"
    strAddresses = ""
    DoCmd.SendObject acSendNoObject, , acFormatTXT, strAddresses, , , strSubject, strBody, True
    Exit Sub
    Error:
    MsgBox Err.Number & " " & (Err.Description)
    Exit Sub
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Error handler works for me - the one in your code, not the one that generates error 13.

    So you don't know if references to other fields of rstChange_Request work?

    Not sure it will make a difference, but SELECT sql normally terminates with semi-colon.
    strSQL = "SELECT * FROM GO_EMail;"

    See nothing wrong with method of referencing fields, but this should also work:
    rstChange_Request!CR_Numbers

    If you want to explicitly declare each variable type, then must be like:
    Dim strSubject As String, strBody As String, strAddresses As String
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    June
    I'll add the colon, and try your references. I think the issue was it being outside the loop.
    Thanks

    I still get Error 3021 No Records found. when I use this code:

    strSubject = "Action Officer Change Request Number " & rstChange_Request!CR_Numbers


    There error handling is fine. I didn't want the 2501 popping up. I wanted to exclude it from the list.

  4. #4
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    The error handler is fixed.

    I used this off the net:
    Error_Handler_Exit:
    Exit Sub

    Error_Handler:
    Select Case Err.Number
    Case 2501
    Err.Clear
    Resume Error_Handler_Exit
    Case Else
    MsgBox "Error No. " & Err.Number & vbCrLf & "Description: " & Err.Description, vbExclamation, "Database Error"
    Err.Clear
    Resume Error_Handler_Exit
    End Select

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Still wondering about Error 3021 No record found part

  6. #6
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I moved a Couple of lines to add the STRSubject, strAddress before the Loop & End if statements
    rstChange_Request.MoveFirst
    strSubject = "CCB Change Request Number " & rstChange_Request("CR_Numbers")
    strAddresses = ""
    DoCmd.SendObject acSendNoObject, , acFormatTXT, strAddresses, , , strSubject, strBody, True
    Do While Not rstChange_Request.EOF
    rstChange_Request.MoveNext
    Loop
    End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error Declaring FK and PK on same Line
    By jo15765 in forum SQL Server
    Replies: 0
    Last Post: 01-21-2012, 04:29 PM
  2. DAO error in Set rst line...
    By tnt in forum Programming
    Replies: 2
    Last Post: 10-06-2011, 12:14 AM
  3. VBA check for email subject line
    By problem_addic in forum Access
    Replies: 4
    Last Post: 03-12-2010, 02:33 PM
  4. Field Name into Subject/Body of an email?
    By Stanggirlie in forum Programming
    Replies: 0
    Last Post: 01-05-2009, 11:51 AM
  5. Email field name into subject/body?
    By Stanggirlie in forum Access
    Replies: 0
    Last Post: 01-02-2009, 11:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums