Search code examples
ms-accessvbamasking

Retrieving value including input mask from TextBox field - Access VBA 2016


I have an input mask of JAAA-AAA on a TextBox, so when the user enters that input field, they will see this: "J___-___".

However, when they fill it out like so, J123-321, and I get the value using [myfield].Value, it says that the value is only 123321. It strips the preset 'J' and '-' I had in there. How can I prevent the stripping of these characters when I retrieve the value from this field?


Solution

  • You need to set the second part of the input mask property to 0.

    If you look at the documentation, you can see it has 3 parts, and the 2nd part controls if the mask is stored with the data, or only the data is stored.

    The final mask property would be the following:

    \JAAA\-AAA;0;_