Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 03-14-2018, 12:39 AM   #16
ridders
Newbee moderator
 
ridders's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 5,566
Thanks: 79
Thanked 1,379 Times in 1,286 Posts
ridders is a jewel in the rough ridders is a jewel in the rough ridders is a jewel in the rough ridders is a jewel in the rough
Re: equential alphanumeric order numbers

If a code error occurs, it would jump to the error handler, show a message and exit. ALL code after the error would be skipped.

With no error handler, it would just crash if a code error occurs.

The error handler helps the developer identify and fix the error.

To test what happens, add this line somewhere in your code
Code:
Err.raise 94
This will trigger error 94 and a message will be shown

Make sure you remove it afterwards!

__________________
Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left and leave a comment.

New example databases:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


-------------------------
nil illegitimi carborundum est

Last edited by ridders; 03-14-2018 at 12:46 AM.
ridders is offline   Reply With Quote
The Following User Says Thank You to ridders For This Useful Post:
donsi (03-14-2018)
Old 03-14-2018, 04:04 AM   #17
donsi
Newly Registered User
 
Join Date: Sep 2016
Posts: 59
Thanks: 35
Thanked 1 Time in 1 Post
donsi is on a distinguished road
Re: equential alphanumeric order numbers

This is where I was getting confused. I was under impression that with err handler, you catch the error, fix it, then resume with the rest of the code. Thanks for clarifying.
Now the question is, how do I permanently fix the error for duplicate form number so it won't need to have an handler.
This DB will be used by multiple users throughout the day, and there might be several occasions when two users may click Submit button at the same time.
donsi is offline   Reply With Quote
Old 03-14-2018, 09:21 AM   #18
Mark_
Longboard on the internet
 
Join Date: Sep 2017
Posts: 1,264
Thanks: 13
Thanked 241 Times in 239 Posts
Mark_ will become famous soon enough
Re: equential alphanumeric order numbers

To simplify your work and to make your code easier to maintain, I would suggest breaking it down into pieces that are easy to work with.

I would make the following functions/subs to do the actual work;
Function Val_Print ‘Function that has all of your field checking. Each of your checks that now exits would simply have this return “FALSE”, otherwise it returns “TRUE”
Sub Assign_Number ‘Sub that assigns the number, saves the record and does error checking
Sub Print_Form ‘Code to actually print the form and prompt if they need to reprint.

Each of these would be the existing piece of code you have move to the function or sub as appropriate. Your commented '================================= looks like you were already trying to get to this result.

This would allow you to concentrate on each piece without having the other code get in the way. Your code for your button would then look like
Code:
IF NOT Val_Print then exit sub	‘If not ready to print, exit out.
Assign_Number
Print_Form
Often by breaking larger pieces of code down into smaller pieces it becomes not only more manageable but also easier to troubleshoot.


Mark_ is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a sequential alphanumeric record to a table joemennell Forms 1 05-18-2015 12:41 AM
Sequential alphanumeric field greenr Forms 2 01-16-2012 06:13 AM
sequential alphanumeric order numbers Bob100 Forms 18 01-16-2011 09:54 AM
Sequential Order Number with Alphanumeric Value manix Tables 13 05-04-2007 11:08 AM
Placing one field from sequential records in sequential order in a report Ben McCall Reports 8 07-02-2001 03:23 PM




All times are GMT -8. The time now is 12:24 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World