Results 1 to 6 of 6
  1. #1
    RingoStarr is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    9

    Need help with Error Handler

    First off, I am still extremely new to VBA and access in general, so please bare with me. Below is a code I am using to send a specific workorder to a technician. The problem I am having is if you back out before sending it, access gives users the ability to debug my code. I know I need to add an error handler but I am clueless on how to do it. Any help is appreciated. Thank you!

    On a side not, I would really like my report to be populated with the company name as the subject automatically but haven't been able to get it to work for some reason. That's more of a secondary concern though. My field for company name is CompanyName.

    Private Sub Email_Workorder_Click()
    Dim strDocName As String


    Dim strWhere As String
    strDocName = "Workorders"
    If Me.Dirty Then Me.Dirty = False
    strWhere = "[WorkorderID]=" & Me!WorkorderID
    DoCmd.OpenReport strDocName, acPreview, , strWhere
    DoCmd.SendObject acSendReport, "Workorders", acFormatPDF, , "CC", "BCC"

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Here are the basics:

    http://www.baldyweb.com/ErrorTrap.htm

    If memory serves, not sending the email throws error 2501, but double check that. If it's a fixed company name, simply enclose it in quotes. If it's coming from the report, you should be able to refer to it since it's open:

    Reports!Workorders.CompanyName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RingoStarr is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    9
    Well that was a very simple fix for the subject, thank you very much! You are correct by the way, it is throwing error 2501. I'm reading the info on the link but still confused on what to enter in this circumstance. Like I said, brand new at this. I'll keep trying to mess with it.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help! You may simply want to get rid of the message box for that error so it fails silently.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    RingoStarr is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    9
    Just got it to work, thank you for all your help!!!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problem, and welcome to the site by the way!

    Keep banging those drums too!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Access Form Requery (F5 on keyboard or reopening) handler?
    By superfury in forum Code Repository
    Replies: 0
    Last Post: 08-23-2013, 03:17 AM
  2. Simple Error Handler
    By Tim777 in forum Access
    Replies: 7
    Last Post: 11-16-2012, 06:23 PM
  3. Replies: 0
    Last Post: 07-16-2012, 05:42 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. Global Error Handler Issue
    By usmcgrunt in forum Programming
    Replies: 1
    Last Post: 11-02-2011, 08:26 PM

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