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.
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.
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
Thank you, that is what I needed.
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
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
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
OK I took the code off and none of my reports are functioning now.
OK all fixed now. It was my error when I copied the code over.
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
Yes it is working. Operator error all the time.