Results 1 to 6 of 6
  1. #1
    dsaxena15 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    18

    Primary key of an exact length

    Hey guys! For my student database, my primary key is the Student_ID. The student ids are exactly 9 characters long. So, I want my primary key to accept inputs which are exactly 9 characters (not less or more). This would avoid inputting bad data. How could I do this?



    I would really appreciate some help. Thanks!

  2. #2
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    You would typically do this using a validation rule in the table or in the Before Update event of your form, but it would be helpful to know what type of data we're dealing with (i.e. numeric, alphanumeric, special characters allowed or not, etc.). You can check for length simply enough with Len(YourField), but that doesn't really tell you much about the validity of the data itself, the user could have entered 8 characters and a space.

  3. #3
    dsaxena15 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    18
    I am not too worried about the 8 characters and a space since its a small database and I'll be the one operating it.I just want the user to be inputting exactly 9 characters. So, my student ID is of type text (eg: 005823421). Could you tell me how to use a validation rule in a table or the Before Update event? I am really new at this and would appreciate your help.

  4. #4
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    For a validation rule in the table, open your table in design view and in the Validation Rule property put;

    Is Null Or Like "?????????"

    then enter some Validation Text. The Validation Text is the message that will appear if the rule is violated.
    Attached Thumbnails Attached Thumbnails Capture.PNG  

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Try the Input Mask property.
    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.

  6. #6
    dsaxena15 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    18
    Got it! Thanks guys!

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

Similar Threads

  1. Matching Non exact Cells
    By Shido151 in forum Access
    Replies: 4
    Last Post: 04-03-2012, 12:03 PM
  2. Query for similar but not exact data
    By markdudley in forum Queries
    Replies: 4
    Last Post: 03-09-2012, 01:02 PM
  3. Replies: 8
    Last Post: 03-01-2012, 08:37 AM
  4. Exact Match Hyperlink
    By JeffG3209 in forum Access
    Replies: 5
    Last Post: 06-23-2011, 07:46 PM
  5. set an exact size for a group section?
    By Coolpapabell in forum Reports
    Replies: 0
    Last Post: 08-21-2009, 08:26 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