Results 1 to 7 of 7
  1. #1
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112

    Scanning table for duplicate entry from VBA

    Hi


    I have a form with unbounded text boxes where a user enters payment details. When he clicks "Submit" I want to scan the table where payment details are stored to see if a duplicate payment had already been made in the past, before I enter this new entry.

    How can I do a scan of the table to see if a duplicate entry exists? I have looked at RunSQL but I don't think it returns a value.

    Thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Maybe you want to look at DCount or DLookup: http://www.mvps.org/access/general/gen0018.htm
    If it is the RecordSource of your form then .FindFirst would be faster.

  3. #3
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Thanks RuralGuy!

    I'm getting a "type mismatch" error when I do this:

    duplicateCount = DCount("[fkStudentID]", "tblFeesPaid", "[fkStudentID] = '" & Me.fkStudentID & _
    "' AND [MonthPaid] = '" & Me.MonthPaid & "'")

    tblFeesPaid.fkStudentID is a number. I checked this part out in the Immediate window and it isn't causing the problem.

    Me is a form that I'm on, and Me.MonthPaid is a text box containing a date.

    tblFeesPaid.MonthPaid is a Date/Time type.

    I tried to do CStr(Me.MonthPaid) and CDate(Me.MonthPaid) but I still get the data type mismatch error.

    Any idea why?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Look at the link I supplied again; especially referring to the three different types of values.

  5. #5
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Ah! Got it! Thanks you!

    No "'" for numbers and "#" for dates..learned something new today.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    By Jove, I think you've got it!

  7. #7
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    heheheh! thanks to you

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

Similar Threads

  1. MsgBox for duplicate entry
    By usmcgrunt in forum Programming
    Replies: 3
    Last Post: 11-09-2010, 08:48 AM
  2. Customer Entry/Find Duplicate/Similar names
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-27-2010, 09:20 PM
  3. Replies: 3
    Last Post: 06-04-2010, 12:47 PM
  4. Duplicate Values in table
    By senthilrg in forum Queries
    Replies: 3
    Last Post: 12-18-2009, 09:24 PM
  5. Duplicate add to new table
    By horseyshoe in forum Access
    Replies: 3
    Last Post: 09-01-2006, 07:51 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