Results 1 to 13 of 13
  1. #1
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26

    Report Debug


    When someone clicks on the button to run a report, then cancels when it asks for a date seeing they ran the wrong report. How do I ger the end/debug error message from showing up. I know it is probably just a simple addition to my code.

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Assume you mean error 2501?
    Use error handling code in the button click event on the calling form similar to this:

    Code:
    Private Sub cmdPrintReport_Click()
    
    
    On Error GoTo Err_Handler
        
        DoCmd.OpenReport "YourReportNameHere", acViewPreview
        
    Exit_Handler:
        Exit Sub
    
    
    Err_Handler:
        If Err = 2501 Then Exit Sub
        MsgBox "Error " & Err.Number & " in line " & Erl & " of cmdPrintReport_Click procedure: " & Err.Description
        Resume Exit_Handler
         
    End Sub
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26
    Thank you, that is what I needed.

  4. #4
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26
    OK I am not sure where to add the different lines, because when I added them were I thought they went the error still occurred. This is the code I currently have there:

    Private Sub CmbSpecialChBtn_Click()
    If TempVars("Username") = "Ken" Or TempVars("Username") = "Staton" Or TempVars("Username") = "Kelly" Then
    DoCmd.OpenReport "CombinedRider-Special Chart", acViewReport
    Else
    MsgBox "Access Denied"
    End If
    End Sub

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You haven't added the code to the event which opens the report

    Code:
    Private Sub CmbSpecialChBtn_Click()
    
    On Error GoTo Err_Handler
        
        If TempVars("Username") = "Ken" Or TempVars("Username") = "Staton" Or TempVars("Username") = "Kelly" Then
               DoCmd.OpenReport "CombinedRider-Special Chart", acViewReport
        Else
               MsgBox "Access Denied"
        End If
        
    Exit_Handler:
        Exit Sub
    
    Err_Handler:
        If Err = 2501 Then Exit Sub
        MsgBox "Error " & Err.Number & " in CmbSpecialChBtn_Click procedure: " & Err.Description
        Resume Exit_Handler
    
    End Sub
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26
    OK after I added the code, now none of the buttons work and I get this error message.
    Click image for larger version. 

Name:	Screenshot 2023-08-01 111921.png 
Views:	12 
Size:	39.5 KB 
ID:	50576

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Message means what is says?
    You have two events with that name.
    Try compiling your code and look for both blocks of code.
    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

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I agree. I said to add the code to that existing event ...not duplicate the event!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26
    OK I took the code off and none of my reports are functioning now.

  10. #10
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26
    OK all fixed now. It was my error when I copied the code over.

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by krc9127 View Post
    OK all fixed now. It was my error when I copied the code over.
    Oh we knew that?
    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

  12. #12
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Yes we did!
    More importantly, is it now working?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  13. #13
    krc9127 is offline Novice
    Windows 11 Access 2007
    Join Date
    Jul 2023
    Posts
    26
    Yes it is working. Operator error all the time.

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

Similar Threads

  1. How to debug a report
    By WCStarks in forum Reports
    Replies: 17
    Last Post: 12-18-2018, 02:35 PM
  2. Debug warning
    By Jaap in forum Access
    Replies: 5
    Last Post: 10-13-2017, 01:24 PM
  3. Help Debug code
    By joym in forum Access
    Replies: 6
    Last Post: 05-24-2017, 04:15 PM
  4. Can't debug a Sub
    By wardw in forum Programming
    Replies: 6
    Last Post: 10-18-2013, 10:03 AM
  5. Debug
    By gio25 in forum Programming
    Replies: 1
    Last Post: 02-08-2011, 08:30 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