Results 1 to 9 of 9
  1. #1
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47

    LIKE "###[-]###" doe not work


    I have a short test field that must be in the format 999-999, that is, three digits, a hyphen and three more digits. I am using an input mask of 000\-000. I also have a validation rule of LIKE "###[-]###" but the validation rule always fails. What is the correct validation rule for data of the form 123-456? Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    queries use LIKE statement uses * or ?.
    mask uses #

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You don't need a validation rule if the input mask indicates what characters are allowed, and which characters are required. MS Access won't allow invalid data to be entered.

  4. #4
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    LIKE "???-???" does not work nor does LIKE "???[-]???". I am still missing something.

  5. #5
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    My problem is not what I thought. LIKE "###-###" works correctly as a validation rule IF I do not have an input mask. However, if I add the input mask 000\-000 the validation rule fails and displays the validation text. So, the real question is, why can't I have both an input mask and a validation rule?

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Did you open the table and look at the value stored in the field?
    Did the value have the hyphen?
    Do you want the store the hyphen as part of the value in the field?

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    ...why can't I have both an input mask and a validation rule?
    You can - except that you have be sure that the two are compatible.

    An important feature of the input mask is this: the literal characters (in your case the "-") are not stored with the data unless you include the second section of the input mask a "0" (Check the help for input mask).

    Your input mask is 000\-000, which means that if you enter what looks like 123-456, what you really get is 123456 as the stored value. But the validation rule is expecting 123-456, so it fails.

    If you change the input mask to 000\-000;0, then when you enter what looks like 123-456 actually gives you 123-456, which passes the validation rule test, and all is well.

  8. #8
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    The value stored in the field does contain the hyphen.
    I do want the hyphen stored in the field.

  9. #9
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    John_G, Thanks. Your solution solved the problem. How do I look at the help for input masks? When I click the input mask field in design view and press F1 I get a Web page that says "Unable to service request". The same is true no matter which property is selected when I press F1.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  2. Replies: 2
    Last Post: 12-04-2012, 01:03 AM
  3. Replies: 2
    Last Post: 09-29-2012, 11:22 PM
  4. Replies: 1
    Last Post: 04-05-2012, 08:26 AM
  5. Replies: 7
    Last Post: 01-19-2011, 10:39 AM

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