Results 1 to 3 of 3
  1. #1
    RachelBedi is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Jul 2012
    Posts
    67

    Duplicate Coding HELP!

    I have designed a database with Master Table as my table name. I have set up an add record button which I need to have prompt someone when they have entered a duplicate Paymode ID number.

    This is the code I have but it is giving an error for ANY number entered into this field even if it's not a duplicate.

    Private Sub Paymode_ID_BeforeUpdate(Cancel As Integer)
    If IsNull(DLookup("[Paymode_ID]", _


    "Master Table", _
    "[Paymode_ID] = """ & Me.Paymode_ID.Text & """")) = False Then
    Cancel = True
    MsgBox "Paymode_ID already exists", vbOKOnly, "Warning"
    Me![Paymode ID].Undo
    End If
    End Sub

    Please help!

  2. #2
    RachelBedi is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Jul 2012
    Posts
    67
    Someone please help! As a note I cannot set the Paymode ID as Indexed Yes (no Duplicates) and I cannot set it as a primary key as I need to allow for null values.

  3. #3
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    If the paymodeID field can be null, that implies that you can have many records where it is null which would be duplicates technically speaking. So I assume that you do not want any duplicates when an actual paymodeID is specified. So you will have to conduct your test to check only those records where the PaymodeID is not null. I would first create a query


    query name: qryNotNullPaymodeID

    SELECT [Master Table].Paymode_ID
    FROM [Master Table]
    WHERE ((Not ([Master Table].Paymode_ID) Is Null));

    I generally prefer to use DCount() instead of DLookup(), so utilizing the above query:


    If DCount("*", "qryNotNullPaymodeID", "Paymode_ID = '" & Me.Paymode_ID & "'")>0 Then
    Cancel = True
    MsgBox "Paymode_ID already exists", vbOKOnly, "Warning"
    Me![Paymode ID].Undo
    End If
    End Sub

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

Similar Threads

  1. Please help with VB coding
    By winterh in forum Import/Export Data
    Replies: 11
    Last Post: 03-19-2012, 06:05 PM
  2. Need help in VBA coding
    By Kcgp in forum Programming
    Replies: 6
    Last Post: 02-01-2012, 11:22 PM
  3. Access without coding
    By kp123 in forum Access
    Replies: 4
    Last Post: 11-25-2011, 03:50 PM
  4. Coding question
    By kzoli62 in forum Access
    Replies: 1
    Last Post: 07-04-2011, 05:09 PM
  5. Bar-Coding
    By texasprincess7 in forum Access
    Replies: 1
    Last Post: 02-12-2009, 10:29 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