Results 1 to 7 of 7
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828

    Runtime Error 13 on preventing a duplicate value with 2 fields?

    Hi all,
    I am trying to prevent a duplicate value on a subform if a dup value is entered and if it has the same ID field as the previous subform ID.
    Code is:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    
    If DLookup("[SystemPrimaryRole]", "tblSystemPrimaryRole", [SystemPrimaryRole] > 0 And [SystemPrimaryIndustryID] = Me.TxtSystemPrimaryIndustryID) Then
        MsgBox "This Primary Role Value has all ready been entered"
        Me.Undo
        Exit Sub
        End If
    End Sub
    Data base is attached, opens to form in question. If you type in Lodging in second subform, it should not allow it but getting error 13?
    Can I get some assistance witht this please?
    Thannks


    Dave

    SystemIndustryData.zip

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    DLookup is missing quote marks and concatenation in the WHERE CONDITION.

    DLookup("[SystemPrimaryRole]", "tblSystemPrimaryRole", "[SystemPrimaryRole] > 0 And [SystemPrimaryIndustryID] = " & Me.TxtSystemPrimaryIndustryID)


    BTW, "all ready" should be "already".
    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
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    Hi June7
    This is getting a syntax error

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    Hi June7
    I am getting error on this? Runtime 3464
    If DLookup("[SystemPrimaryRole]", "tblSystemPrimaryRole", "[SystemPrimaryRole] > 0 And [SystemPrimaryIndustryID] = " & Me.TxtSystemPrimaryIndustryID) Then
    Data Type Mismatch

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    HI June7
    Thank you, I got it to work!
    Again, thank you very much
    If DLookup("[SystemPrimaryRole]", "tblSystemPrimaryRole", "[SystemPrimaryRole] And [SystemPrimaryIndustryID] = " & Me.TxtSystemPrimaryIndustryID) > 0 Then
    Dave

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    DLookup will return Null if there is no match. Most would use: If Not IsNull(DLookup(...)) Then

    DCount is the only domain aggregate that will return 0 if there is no match.
    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.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,552
    Quote Originally Posted by d9pierce1 View Post
    Hi June7
    This is getting a syntax error
    Compile your code before trying to use it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 2
    Last Post: 02-28-2013, 10:06 AM
  2. Preventing duplicate data entrry
    By FJM in forum Forms
    Replies: 4
    Last Post: 07-16-2012, 07:12 AM
  3. Replies: 1
    Last Post: 04-25-2012, 01:57 PM
  4. preventing duplicate records
    By Alliana Gray in forum Access
    Replies: 6
    Last Post: 08-11-2011, 01:18 PM
  5. Runtime error in preventing duplicates code
    By emilyrogers in forum Access
    Replies: 10
    Last Post: 10-07-2010, 08:14 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