Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Home > TechHelp > Directory > Access > InputBox > Handle Intentional OpenForm Error 2501 by Constance Britten >
Back to InputBox    Comments List
Upload Images | @Reply | Bookmark | Link | Email | Next Unseen |
Handle Intentional OpenForm Error 2501
Constance Britten 
       
25 hours ago
For D02.04's homework we're given the hint to use InputBox for user input. So here I am, trying to get up to speed on InputBox. 8-}

Anyway, unfortunately, I'm seeing something unexpected. After clicking on the "Manager Menu" button on the Main Menu form, and entering either an incorrect or a blank password in the InputBox popup, immediately after I hit OK on my subsequent "Wrong!" MsgBox popup, the Visual Basic run-time error 2501 popup "The OpenForm action was canceled" is displayed.

In the video, this error popup only appears after Richard hits "Cancel" on the InputBox popup at ~9:52. My issue is that I'm also getting that same error message when I enter an incorrect or blank password into the InputBox popup.

I'm running Access 2024 LTSC under Windows 11.

And yes, the "On Error Resume Next" line in the "Manager Menu" button's OnClick event masks this error nicely. But it makes me nervous to mask all errors like that. Is there a more graceful way to deal with this kind of thing?
Constance Britten OP  @Reply  
       
25 hours ago

Constance Britten OP  @Reply  
       
25 hours ago

Richard Rost  @Reply  
           
10 hours ago
Hi Constance. Go by the error dialog here: it's 2501, not 2601. All three cases make sense. If the Manager Menu's On Open event sets Cancel = True, Access stops opening the form and reports 2501 back to the button's DoCmd.OpenForm call. It doesn't matter whether you clicked Cancel, hit OK with nothing entered, or typed a wrong password. In the last two cases, you see your Wrong message first, then Access reports the cancellation.

You're right not to hide every error. In the button's On Click procedure, route errors from the OpenForm call to an error handler. Exit quietly for 2501 from that call, since the form was intentionally canceled. For anything else, show the error number and description so you can see what actually went wrong. My Error Handling video shows how to set that up with On Error GoTo.
Richard Rost  @Reply  
           
10 hours ago
I updated the subject. You typed 2601.
Richard Rost  @Reply  
           
10 hours ago
Constance, check out User Level Security, Part 2. Look for the second method, where I cancel the form in its On Open event and then handle the error in the code that called DoCmd.OpenForm. That shows exactly where the handler goes. For your button, I'd stick with the narrower version above: ignore 2501 from that OpenForm call, and let other errors show.
Constance Britten OP  @Reply  
       
10 hours ago
Thanks Richard for posting! Sorry about the incorrect error number, that's due either to my bad eyesight or a typo, can't say which at this point.

I agree - we absolutely do need to be doing proper error handling, I would like to start implementing that now. Thanks for the pointers!

(And BTW I could not figure out how to make use of InputBox for D02.04's homework, since it only has one text box for user input and we needed three. I used a modal form with most of its form code borrowed from your Login Form TechHelp. But it was good to learn about InputBox.)

(Oh, and let me register one more vote for homework assignments. I loved doing D02.04's.)
Richard Rost  @Reply  
           
9 hours ago
That was a good use of a modal form, Constance. InputBox gives you one value at a time, but the form lets you collect all three together. And thanks for the vote for more homework. I like hearing which exercises you enjoy working through.
Add a Reply Upload an Image
Next Unseen

 
 
What's This?

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 11/30/2026 1:06:26 AM. PLT: 1s