I agree. seems like an odd control to do this with.Wait a minute. Combobox has no problem listing data in both structures. Is this combobox used for selecting only existing values or does combobox allow input of values not in list?
I agree. seems like an odd control to do this with.Wait a minute. Combobox has no problem listing data in both structures. Is this combobox used for selecting only existing values or does combobox allow input of values not in list?
If this helped, please click the star * at the bottom left and add to my reputation- Thanks
The first two letter (AB or CD) will be captured first based on user selection (using a combo box or other controls as June7 suggestion) . And then based on that, I use the codes as moke123 suggestion. I will take notes your Keypress event, too.
If combobox is only for selecting existing values, why bother with input mask? Is data saved with the punctuation?
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Yes, but if the punctuation is saved (and it looks like your input masks are set to save), they can simply type whichever structure they want. The input mask is then only useful if user is allowed to enter values not in list. Or maybe it would be useful aid for typing the value. I need to do some testing.
Okay, tested. Input mask is helpful. However, if user accidentally selects wrong structured value from dropdown list, it errors. Might want to also filter the list. This is called "cascading" or "conditional" combobox.
Student combobox RowSource like:
SELECT StudentNo FROM Students WHERE StudentNo LIKE [cbxPre] & "*";
VBA:
This arrangement means user will likely type AB or CD prefix twice. Kind of annoying.Code:Private Sub cbxPre_AfterUpdate() Me.cbxStudent.InputMask = IIf(Me.cbxPre = "AB", "AB-999\-9999\-9999;0", "CD-999\-999999999;0") Me.cbxStudent.Requery End Sub
Last edited by June7; 02-21-2024 at 01:47 AM.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Thank you for the idea. Actually, the "AD" and "CD" are only values to be used. Therefore, these values need to be captured first to determine which input masks they need to follow. So I think the combo box is for user to select either one of these value and then the next textbox will show the value the user selected and the format (input mask) they will follow to enter their numbers. I think using the If and Else If statement in this case.Yes, but if the punctuation is saved (and it looks like your input masks are set to save), they can simply type whichever structure they want. The input mask is then only useful if user is allowed to enter values not in list. Or maybe it would be useful aid for typing the value. I need to do some testing.
Okay, tested. Input mask is helpful. However, if user accidentally selects wrong structured value from dropdown list, it errors. Might want to also filter the list. This is called "cascading" or "conditional" combobox.
Student combobox RowSource like:
SELECT StudentNo FROM Students WHERE StudentNo LIKE [cbxPre] & "*";
VBA:
This arrangement means user will likely type AB or CD prefix twice. Kind of annoying.Code:Private Sub cbxPre_AfterUpdate() Me.cbxStudent.InputMask = IIf(Me.cbxPre = "AB", "AB-999\-9999\-9999;0", "CD-999\-999999999;0") Me.cbxStudent.Requery End Sub
You are right. The input mask is used to aid data entry following the required format.
Last edited by Pada; 02-21-2024 at 07:49 AM. Reason: Aid more information
Actually in your case only the first character needs to be captured to determine which mask to use?
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
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
Welsh made a valid point. User needs to provide only A or C to determine which mask to apply. Could modify comboboxes and code to do that.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
This comes close. The difficult part is figuring out what mistakes a user may make and how to handle them.
In the attached pressing the escape key will reset the input mask.
Needs a little more experimenting.
If this helped, please click the star * at the bottom left and add to my reputation- Thanks
Users have been trained to enter only AB or CD. I use an input box that pops up and prompt user to enter either AB or CD. If no AB or CD entered then nothing happens.
Thank you, moke123, I will try your codes.
Last edited by Pada; 02-22-2024 at 04:26 PM. Reason: Add more info
My code loads the mask on the first keystroke using A, a, C, or c. The cursor then moves to the first digit position.
Any other key besides A or C fires a message box. Hitting Escape will clear the textbox and mask.
Still needs some cleanup and experimenting but works OK.
Edit: Made a few changes, one being able to tab past the textbox without issues.
If this helped, please click the star * at the bottom left and add to my reputation- Thanks