Form event to catch Issue

Hello,
An item number is always 7 digits. So if my item is 456, by format is should be 0000456. Now there is a access form where users will be entering the number for new items – how do I build the form so that it check for the correct data entry – or if the users enter 456, the form converts that entry to add 4 extra zeroes in front of the that number and then stores it in the table?  Any ideas

Thank you
RayneAsked:
Who is Participating?
 
Dale FyeConnect With a Mentor Commented:
Don't use the BeforeUpdate, use AfterUpdate
0
 
Dale FyeCommented:
You could use the AfterUpdate, LostFocus, or Exit event of the control, something like:

Private Sub txt_ItemNumber_AfterUpdate

    me.txt_ItemNumber = Right("0000000" & txt_ItemNumber, 7)

End Sub

This would add 7 zeros to the left of the ItemNumber and then take the right most 7 characters.  Make sure your ItemNumber field is formatted as text, because if it is numeric, the leading zeros will be dropped.
0
 
RayneAuthor Commented:
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
RayneAuthor Commented:
Hello Dale,

I got error and on debug it gave me this….see attached
0
 
RayneAuthor Commented:
I did used it, its not adding in the zeroes before and storing the way the number is typed in
0
 
Dale FyeCommented:
Did you use the Form_Afterupdate or the control afterupdate.  If you used the control afterupdate, it should save it properly when you save the form.
0
 
RayneAuthor Commented:
yup yup it worked, thank you Dan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.