Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Pada is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2023
    Posts
    22

    A dropdown list with two pre-defined InputMasks property

    I have a data entry field, [Student No.], with two pre-defined formats with input masks as following.

    AB-999\-9999\-9999;0 and
    CD-999\-999999999;0


    In the table's field property, there is only one Input Mask property, but I need to have two different input masks as showed above.



    How can I create a dropdown list for the [Student No.] field that allows users to select either one of these two values on the list above.

    Thank you very much in advance for your help.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Have another control where student selects type AB or type CD. Then code changes InputMask property of combobox.
    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.

  3. #3
    Pada is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2023
    Posts
    22
    Thanks, June7 for the idea. Do you mean I should create a new combo box dropdown for two values, AB and CD, next to the StudentNo. for user selection? When user select either AD or CD, programming will capture the selected value and add the corresponding pre-defined inputmask property?

    If you post sample of codes for these combo boxes, I would appreciate it.

    Thank you!

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Simple If statement and set mask.
    https://learn.microsoft.com/en-us/of...tbox.inputmask

    Could possibly do it on the OnChange event of the textbox?
    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

  5. #5
    Pada is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2023
    Posts
    22
    Sorry, I forgot to post that based on the 1st two characters, AD or CD to set the input masks as showed. Looks like June7 knows that even I didn't say that. I am trying to figure should I add another combo box so that when user clicks and select one of them and programming the input mask correspondingly.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Could use a combobox or an option group with radio buttons or checkboxes or toggle buttons.

    Regardless, code would be a simple If Then Else structure.

    Is prefix AB or AD?
    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.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Could also test for first character entered and then set the mask perhaps?
    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

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Welsh, what event would you suggest? The Change event will trigger with each keystroke in box.
    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.

  9. #9
    Pada is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2023
    Posts
    22
    June7, sorry again for typo. It is AB. Thank you for your idea. I will work in that.
    Last edited by Pada; 02-20-2024 at 12:23 AM. Reason: Just replying to the thread

  10. #10
    Pada is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2023
    Posts
    22
    Welsh, I think I will use form Current event. With this event, the form will show the current values of AB and CD and will show the pre-defined input masks.

  11. #11
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    How about something in the keypress event?

    (untested)
    Code:
    Private Sub Text5_KeyPress(KeyAscii As Integer)
     
        If Len(Me.Text5.Text) > 1 Then Exit Sub
    
        Select Case KeyAscii
    
            Case 65, 97
                Me.Text5.InputMask = "AB-999\-9999\-9999;0"
            Case 67, 99
                Me.Text5.InputMask = "CD-999\-999999999;0"
            Case Else
                MsgBox "Must start with A or C"
                Me.Text5.InputMask = ""
                KeyAscii = 0
        End Select
        
        Me.Text5.Requery
    
    End Sub
    You'll need to tweak it a lot to deal with various scenarios but it may be the correct event.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by June7 View Post
    Welsh, what event would you suggest? The Change event will trigger with each keystroke in box.
    Yes, I am aware but the field length is small. Just offering another method? Could even test for length and ignore code after the first keystroke?
    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

  13. #13
    Pada is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2023
    Posts
    22
    Moke123, thanks for the idea and the codes. I will take notes.

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Pada View Post
    Welsh, I think I will use form Current event. With this event, the form will show the current values of AB and CD and will show the pre-defined input masks.
    Not when you are keying it in though, surely. Might need both two events in that case,
    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

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    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?
    Last edited by June7; 02-20-2024 at 10:10 PM.
    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.

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 09-16-2023, 08:54 AM
  2. Dropdown List Box-Memo List
    By trident in forum Forms
    Replies: 3
    Last Post: 11-19-2016, 12:29 PM
  3. user defined property
    By Jen0dorf in forum Access
    Replies: 4
    Last Post: 04-25-2016, 12:45 AM
  4. Replies: 8
    Last Post: 01-31-2015, 11:34 AM
  5. Add to the dropdown list
    By tanyalee123 in forum Forms
    Replies: 1
    Last Post: 11-13-2013, 01:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums