Results 1 to 6 of 6
  1. #1
    ResearchRN is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Location
    St. Louis, Mo.
    Posts
    21

    Problem with code to prevent duplicate entries

    I'm a research nurse in neurosurgery. I have a database of brain tumor cases. I wanted to add some code to the medical record number field in my demographics form to (1) alert the user if a medical record number they are trying to enter is already in the database and then (2) take them to that record. Here's the code:
    Code:
    Private Sub mrNum_BeforeUpdate(Cancel As Integer)
    Dim mrn As String
    Dim LinkCriteria As String
    Dim rsc As DAO.Recordset
    Set rsc = Me.RecordsetClone
    mrn = Me.mrNum.Value
    LinkCriteria = "[mrNum]=" & "'" & mrn & "'"
    'Check tblDemographics for duplicate Medical Record Number
    If DCount("mrNum", "tblDemographics", _
    LinkCriteria) > 0 Then
    'Undo duplicate entry
    Me.Undo
    'Message box warning of duplication
    MsgBox "Warning that medical record number has already been entered." _
    & vbCr & vbCr & "You will now been taken to the record.", _
    vbInformation, "Duplicate Information"
    'Go to record of original record
    rsc.FindFirst stLinkCriteria
     
    Me.Bookmark = rsc.Bookmark
    End If
    Set rsc = Nothing
    End Sub
    The problem is in line 18 "rsc.FindFirst stLinkCriteria". I get a Run-time error 3077 "Syntax error (missing operator) in expression." I've tried everything I know but I can't figure out what I'm doing wrong. Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Your variable is named LinkCriteria, not stLinkCriteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ResearchRN is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Location
    St. Louis, Mo.
    Posts
    21
    Quote Originally Posted by pbaldy View Post
    Your variable is named LinkCriteria, not stLinkCriteria.
    Doh! Just goes to show, it's the little things. Thanks very much

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You didn't fix it, you added to the problem. The variable you set a value to is:

    LinkCriteria = "[mrNum]=" & "'" & mrn & "'"

    Then you use stLinkCriteria, which would have no value (unless you're setting it someplace else). Add this line and see what gets output to the Immediate window:

    Debug.Print stLinkCriteria
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ResearchRN is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Location
    St. Louis, Mo.
    Posts
    21
    Quote Originally Posted by pbaldy View Post
    You didn't fix it, you added to the problem. The variable you set a value to is:

    LinkCriteria = "[mrNum]=" & "'" & mrn & "'"

    Then you use stLinkCriteria, which would have no value (unless you're setting it someplace else). Add this line and see what gets output to the Immediate window:

    Debug.Print stLinkCriteria
    Thanks, I did fix that that line as well. Also added the "Debug" line as you suggested. Works perfectly.

    Since this is my first thread, how do you mark a thread as solved?

    Thanks again.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad it worked. You can take out the Debug line, as it's only used for debugging problems. You can mark a thread solved using "Thread Tools" up at the top of the thread.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Dcount prevent duplicate
    By ayamali in forum Programming
    Replies: 20
    Last Post: 04-16-2013, 09:31 PM
  2. Prevent Duplicate Entry
    By kilosierra71 in forum Forms
    Replies: 4
    Last Post: 07-28-2011, 03:08 PM
  3. Replies: 2
    Last Post: 02-12-2011, 09:54 PM
  4. prevent editing current entries in forms
    By Chazcoral in forum Forms
    Replies: 1
    Last Post: 05-20-2010, 06:49 PM
  5. Prevent Duplicate Values on Combination of Two Fields
    By LornaM in forum Database Design
    Replies: 8
    Last Post: 05-05-2009, 11:16 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