Results 1 to 4 of 4
  1. #1
    sanal is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Feb 2018
    Posts
    43

    How to replace the access message with more specific user friendly message while entering duplicate


    How to replace the acces message with more specific user friendly message while entering duplicate values in a primary key field. Year field and month field combined used as primary key. when the user make duplicate entry for the month of April 2018 a message will appear as " You entered the month April 2018 twice ".

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,418
    look to the bottom of this thread for many answers to the same question

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,798
    You can research to find the more-or-less complete list of error codes and write code to trap specific ones, or you can purposely perform an action that will cause a specific error. Then you write an error handling routine and use either Case Select or IF block to present your custom message in a message box. No additional form is needed, unless you have the requirement for such. The are tons of examples on how to write these, so it doesn't make a whole lot of sense to provide an example here, especially if it isn't complex enough for your needs. What they will all have in common is that at the appropriate place(s) in your code, you will have a statement like On Error GoTo YourLineLabelNameHere. Usually that goes right after the Dim statements. Be sure your code includes an exit block that a) provides an exit point; b) closes/resets/destroys any objects you have created that exist only in the procedure this code is running from, or else code execution will move right into the error handler.

    EDIT: forgot to mention that this is a vital part of a db that operates with a minimum of system generated error messages. You should try to anticipate as many user "mistakes" as possible and handle any that seem probable. For instance, you might try to enter text in a number field (or vice versa) or too many characters, or no data at all, etc. I'm assuming you're using vba code. I don't use macros and can't even tell you if the latest version has any error handling possibilities at all. Macros have never had error handling capabilities in the past.
    Last edited by Micron; 05-12-2018 at 12:12 PM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would add:

    Quote Originally Posted by sanal View Post
    How to replace the acces message with more specific user friendly message while entering duplicate values in a primary key field. Year field and month field combined used as primary key. when the user make duplicate entry for the month of April 2018 a message will appear as " You entered the month April 2018 twice ".
    "Year" and "Month" are reserved words in Access and shouldn't be used as object names. Reserved words in Access



    I would be better (IMHO) to use an Autonumber field as the PK field and set a compound INDEX on the Year field and month field.

    Microsoft Access Tables: Primary Key Tips and Techniques


    AutoNumber
    ----------------
    Purpose Use an AutoNumber field to provide a unique value that serves no other purpose than to make each record unique. The most common use for an AutoNumber field is as a primary key.


    Autonumbers--What they are NOT and What They Are

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

Similar Threads

  1. Replies: 7
    Last Post: 03-17-2016, 05:53 PM
  2. Replies: 1
    Last Post: 02-09-2016, 09:03 PM
  3. Replies: 1
    Last Post: 10-28-2014, 12:54 PM
  4. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  5. Replies: 4
    Last Post: 08-26-2010, 09:44 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