Results 1 to 8 of 8
  1. #1
    wattles is offline Novice
    Windows 11 Access 2016
    Join Date
    Nov 2023
    Posts
    3

    Dreadful array indexes out of bounds

    I am a newbie when it comes to VB ans I'm trying to send emails from Access 2016 but I recieve and "array Index" error which I do not understand ans cannot apply it to my code......can anyone throw some light on it? Code below

    ' Send the email using rst! from strSQL

    oMail.Body = "Hi, " & rst![FirstName] & " " & rst![Surname] & ", Please find attached your Subscription Reminder for the current year!"
    oMail.Subject = "Subscription Invoice"
    oMail.To = rst!Email
    oMail.Attachments.Add CurrentProject.Path & "" & stDocName & ".pdf"
    oMail.SendUsingAccount = oApp.Session.Accounts.Item(2)
    oMail.Send

    Set oMail = Nothing
    Set oApp = Nothing
    Set rst = Nothing

    '+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++

    DoCmd.Close acReport, stDocName, acSaveNo



    Msgbox "The Subscription Invoice for " & rst![FirstName] & " " & rst![Surname] & " has been sent."






    Exit_CmdSubInvoice_Click:
    Exit Sub


    Err_CmdSubInvoice_Click:
    Msgbox Err.Description
    Resume Exit_CmdSubInvoice_Click

    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Do you have 3 email accounts?, as arrays start at 0.

    Run this code and see what you have
    Code:
    Function MailAccountNumber()
    'Don't forget to set a reference to Outlook in the VBA editor
        Dim outApp As Outlook.Application
        Dim i As Long
    
    
        Set outApp = CreateObject("Outlook.Application")
    
    
        For i = 1 To outApp.Session.Accounts.Count
    '        If InStr(1, "xxxxxxx", outApp.Session.Accounts.item(i)) Then
    '            MailAccountNumber = i
    '            Exit For
    '        End If
            Debug.Print outApp.Session.Accounts.item(i) & " : This is account number " & i
        Next i
        Set outApp = Nothing
    End Function
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Please post code between CODE tags - use # icon on edit toolbar.

    Which line triggers error? Disable error handler and step through code. You should probably post the entire procedure.

    Welsh, I have only one email account and function returns 1 as the number.
    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.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Really?
    My bad then, but my code should show what O/P has.
    I was just assuming the account as that appears to be the only use of an array?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    It's not zero because Session.Accounts.Item(n) is not an array, it's a collection? Not sure what any of that code has to do with an array error message.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    @wattles: can you please post the entire VBA procedure with the declarations and showing the recordset looping?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    wattles is offline Novice
    Windows 11 Access 2016
    Join Date
    Nov 2023
    Posts
    3
    [QUOTE=Gicu;518914]@wattles: can you please post the entire VBA procedure with the declarations and showing the recordset looping?

    Cheers,[/QUOTE

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    [QUOTE=wattles;518942]
    Quote Originally Posted by Gicu View Post
    @wattles: can you please post the entire VBA procedure with the declarations and showing the recordset looping?

    Cheers,[/QUOTE
    ????????
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. SQL Indexes
    By Bulzie in forum SQL Server
    Replies: 5
    Last Post: 11-11-2021, 10:17 AM
  2. Help with indexes
    By PubCrawl in forum Access
    Replies: 8
    Last Post: 12-19-2020, 01:17 AM
  3. Replies: 3
    Last Post: 02-26-2019, 07:27 PM
  4. Too Many Indexes
    By cbrsix in forum Database Design
    Replies: 22
    Last Post: 11-07-2011, 11:12 AM
  5. Bounds fields trouble
    By accessnewb in forum Programming
    Replies: 12
    Last Post: 08-08-2011, 02:18 PM

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