Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    valeriej42 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2013
    Posts
    9

    Access 2003 Prevent duplicate entries based on 3 criteria

    I have a form to enter training by employee. If the training number, employee and date all together have already been entered I need it to not allow it. If any one of the three is different it can be entered.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,918
    Options:

    1. set those fields as a compound key in the table

    2. VBA code in form BeforeUpdate event to validate by checking the entries against data in table, something like:
    If DLookup("ID", "tablename", "trainingNum=" & Me.box1 & " AND EmpNum=" & Me.box2 & " AND datefield=#" & Me.box3 & "#") > 0 Then
    MsgBox "Data already entered."
    Cancel = True
    End If
    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
    valeriej42 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2013
    Posts
    9
    I guess part of the problem lies in that these don't come from a single table. That seems to be where a big part of the problems lies. This is a pretty large, old database. I didn't create it I just have to fix it.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I guess part of the problem lies in that these don't come from a single table.
    DLOOKUP works against queries too. So if you create a query that returns all the values you need from your various tables, it seems you should be able to use June's second suggestion .

  5. #5
    valeriej42 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2013
    Posts
    9
    I am very much a noob when it comes to this. I ran a query which made a new table with the data I needed. I used it in the code and got an error that I cancelled the operation.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Is 'training number' defined as an actual Number, or as Text? It makes a difference in the syntax!

    The code June7 gave presumes that it is defined as a Number Datatype, but things like ID numbers, telephone numbers, etc, often are defined as Text. Unless you're planning on doing math with an all-digit Field, it probably should be defined as Text!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I am very much a noob when it comes to this. I ran a query which made a new table with the data I needed. I used it in the code and got an error that I cancelled the operation.
    You don't need a Make-Table Query. You can just leave it as a simple Select Query, and have the DLOOKUP reference that (the second argument can be the name of a query instead of the name of a table).

    If you are still having problems, post your DLOOKUP formula attempt.

  8. #8
    valeriej42 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2013
    Posts
    9
    Training number is an autonumber. It actually comes from another form where new training is entered and gives it a number. Employee ID is text.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,918
    Yes, criteria for text fields must have apostrophe delimiters, like:

    [Training]='" & Me.Training & "' AND

    I don't think the message was an error, but was a notice that the record update was canceled because the DLookup returned a value so the criteria were found.
    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.

  10. #10
    valeriej42 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2013
    Posts
    9
    I am so lost. I tried again and now I'm getting a syntax error. I'm about ready to chunk the whole PC. This isn't even the only problem I have. Just one I'm trying to solve today. Code is below.

    If DLookup("Employee_ID", "TBL_EmpTrainDate", "Train_Num=" & Me.CB_TrainNo & " AND Employee_ID='" & Me.CB_AssociatedEmployee & " AND Date_Completed=#" & Me.Date_Completed & "#") > 0 Then
    MsgBox "Data already entered."
    Cancel = True
    End If

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,918
    Employee_ID field is text?

    Delimiters must be in pairs. You are missing the second one. Look at the example again.
    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.

  12. #12
    valeriej42 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2013
    Posts
    9
    I guess I don't understand what you are saying.

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,918
    Missing the second apostrophe:

    & " AND Employee_ID='" & Me.CB_AssociatedEmployee & "' AND
    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.

  14. #14
    valeriej42 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2013
    Posts
    9
    Guess I'm still getting it wrong. I'm getting a syntax error on Employee_ID.

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,918
    If you corrected the code as instructed should work.

    Otherwise, provide db for analysis. Follow instructions at bottom of my post. Identify the form involved in issue.
    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 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 11-17-2012, 03:07 PM
  2. Delete Duplicate Records Based on Criteria
    By chadd in forum Queries
    Replies: 2
    Last Post: 02-07-2012, 04:24 PM
  3. Replies: 8
    Last Post: 01-29-2012, 12:50 PM
  4. Replies: 1
    Last Post: 01-04-2012, 01:39 PM
  5. Problem with code to prevent duplicate entries
    By ResearchRN in forum Programming
    Replies: 5
    Last Post: 11-08-2011, 12:12 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