Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Post your code that you used when the error occurred. Use "Go Advanced" within this forum's tools and choose the hashtag # to enclose your code with quote tags (retain formatting).

    Indicate which line of code is causing the exception. You can see which line this is by choosing Debug when the error occurs.

  2. #17
    Baldeagle is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    #Private Sub Command62_Click() Dim varItem As Variant 'Selected items
    Dim strWhere As String 'String to use as WhereCondition
    Dim strDescrip As String 'Description of WhereCondition
    Dim lngLen As Long 'Length of string
    Dim strDelim As String 'Delimiter for this field type.
    Dim strDoc As String 'Name of report to open.
    Dim db As Database
    Dim rs As DAO.Recordset
    Dim ToVar As String
    Dim sql As String
    Dim strEmail As String

    strDelim = """" 'Delimiter appropriate to field type.
    strDoc = "July Cheque Email"

    'Loop through the ItemsSelected in the list box.
    With Me.lstCategory
    For Each varItem In .ItemsSelected
    strWhere = ""
    strDescrip = ""

    If Not IsNull(varItem) Then
    'Build up the filter from the bound column (hidden).
    strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim & ","
    'Build up the description from the text in the visible column.
    strDescrip = strDescrip & """" & .Column(0, varItem) & """, "
    strEmail = Column(1, varItem)

    End If

    'Remove trailing comma. Add field name, IN operator, and brackets.
    ' lngLen = Len(strWhere) - 1
    ' If lngLen > 0 Then
    ' strWhere = "[Name of Mission] IN (" & Left$(strWhere, lngLen) & ")"
    lngLen = Len(strDescrip) - 2
    If lngLen > 0 Then
    strDescrip = "Email: " & Left$(strDescrip, lngLen)
    End If
    ' End If

    'Report will not filter if open, so close it.
    If CurrentProject.AllReports(strDoc).IsLoaded Then
    DoCmd.Close acReport, strDoc
    End If

    DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere, OpenArgs:=strDescrip
    DoCmd.SendObject acSendReport, strDoc, acFormatPDF, strEmail, , , "Payment from Bangor Worldwide Missionary Convention", "Attached is a Notice of money sent to the Bangor Worldwide Missionary Convention for your Organisation. ", True
    DoCmd.Close acReport, strDoc
    Next

    End With
    DoCmd.Close acReport, strDoc


    End Sub#
    The error message is as described earlier. Thanks for your patience.

  3. #18
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    change
    strEmail = Column(1, varItem)

    to
    strEmail = .Column(1, varItem)

    or
    strEmail = Me.lstCategory.Column(1, varItem)

  4. #19
    Baldeagle is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    Progress!! Below is the code that I have used -
    #Private Sub Command62_Click() Dim varItem As Variant 'Selected items
    Dim strWhere As String 'String to use as WhereCondition
    Dim strDescrip As String 'Description of WhereCondition
    Dim lngLen As Long 'Length of string
    Dim strDelim As String 'Delimiter for this field type.
    Dim strDoc As String 'Name of report to open.
    Dim db As Database
    Dim rs As DAO.Recordset
    Dim ToVar As String
    Dim sql As String
    Dim strEmail As String

    strDelim = """" 'Delimiter appropriate to field type.
    strDoc = "July Cheque Email"

    'Loop through the ItemsSelected in the list box.
    With Me.lstCategory
    For Each varItem In .ItemsSelected
    strWhere = ""
    strDescrip = ""

    If Not IsNull(varItem) Then
    'Build up the filter from the bound column (hidden).
    strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim & ","
    'Build up the description from the text in the visible column.
    strDescrip = strDescrip & """" & .Column(0, varItem) & """, "
    strEmail = .Column(1, varItem)

    End If

    'Remove trailing comma. Add field name, IN operator, and brackets.
    ' lngLen = Len(strWhere) - 1
    ' If lngLen > 0 Then
    ' strWhere = "[Name of Mission] IN (" & Left$(strWhere, lngLen) & ")"
    lngLen = Len(strDescrip) - 2
    If lngLen > 0 Then
    strDescrip = "Email: " & Left$(strDescrip, lngLen)
    End If
    ' End If

    'Report will not filter if open, so close it.
    If CurrentProject.AllReports(strDoc).IsLoaded Then
    DoCmd.Close acReport, strDoc
    End If

    'DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere, OpenArgs:=strDescrip
    DoCmd.SendObject acSendReport, strDoc, acFormatPDF, strEmail, , , "Payment from Bangor Worldwide Missionary Convention", "Attached is a Notice of money sent to the Bangor Worldwide Missionary Convention for your Organisation. ", True
    DoCmd.Close acReport, strDoc
    Next

    End With
    DoCmd.Close acReport, strDoc


    End Sub#

    I had to comment out the DoCmdOpenReport line as well. But it has worked and sent the email to both email addresses. However the attachment wasn't the selected one. Can we now try the final step and sort out the Mission Reports please?

  5. #20
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I think I was confused earlier. I thought one of the string variables was assigning an alias to the Email address

    so try un-commenting the code previously commented

    Code:
    'Remove trailing comma. Add field name, IN operator, and brackets.
                      lngLen = Len(strWhere) - 1
                      If lngLen > 0 Then
                      strWhere = "[Name of Mission] IN (" & Left$(strWhere, lngLen) & ")"
                      lngLen = Len(strDescrip) - 2
                      If lngLen > 0 Then
                      strDescrip = "Email: " & Left$(strDescrip, lngLen)
                      End If
                      End If

  6. #21
    Baldeagle is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    Brilliant!! Problem solved. Thanks for your patience and help - very much appreciated.

  7. #22
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Sorry I got side tracked but I am glad you were able to resolve the issue.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 08-16-2013, 04:15 PM
  2. Finding email addresses using VBA
    By P.Malius in forum Programming
    Replies: 1
    Last Post: 07-04-2012, 07:17 AM
  3. send email to email addresses in database?
    By cnstarz in forum Access
    Replies: 5
    Last Post: 03-02-2011, 09:46 PM
  4. Exporting Outlook email addresses
    By noidea in forum Import/Export Data
    Replies: 0
    Last Post: 08-01-2009, 01:48 PM
  5. Combining two Email Addresses
    By Frodo in forum Access
    Replies: 0
    Last Post: 09-16-2007, 07:07 AM

Tags for this Thread

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