Results 1 to 8 of 8
  1. #1
    talktime is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    21

    How to prevent duplicate records

    we have a database of students, where we maintain their particulars specially fee fee history, i.e. which students have paid their fee and who have not yet paid. For this purpose we generate a fee slip every month.




    When i click the 'Generate' button on the form, a required fee slip is generated for the selected month and student.
    But the problem is that when i click the generate button again the same fee slip is generated again for the same selected month, which i don't want to be so. i want to change this behavior like if fee slip for a particulars month say May or June exists, the duplicate should not be generated if the button is click again and again.
    i have provided the sample of Fee Slip Generate 'form' and 'report' to understand the problem.
    i have also provided VBA code of the Generate button. please help.
    Private Sub Command32_Click()

    Dim dbs As Database
    Dim Months As Integer
    Dim mdate As Date

    Set dbs = CurrentDb()
    Me.Text26 = CDate("01" & "/" & Month(Me.Text26) & "/" & Year(Me.Text26))
    Me.Text28 = CDate("01" & "/" & Month(Me.Text28) & "/" & Year(Me.Text28))
    Months = Month(Me.Text26)
    mdate = Me.Text26

    If Me.Frame0.Value = 1 Then
    DoCmd.OpenQuery "School Selected"
    ElseIf Me.Frame0.Value = 2 Then
    DoCmd.OpenQuery "Class Selected"
    ElseIf Me.Frame0.Value = 3 Then
    DoCmd.OpenQuery "Class&Section Selected"
    ElseIf Me.Frame0.Value = 4 Then
    DoCmd.OpenQuery "Student Selected"
    End If

    'MsgBox& Year(Me.Text28)
    DoCmd.OpenQuery "Delete Transport Charges" ' Delete all those record have transport charges but no bus no.
    DoCmd.OpenQuery "Delete Free Transport Records" ' Delete all those record have transport charges but FREE.
    DoCmd.OpenQuery "Deduct Concession"
    DoCmd.OpenQuery "Tuition Fee is zero" ' Delete where tuition fee =0

    While mdate <= Me.Text28
    dbs.Execute "Update [Tmp School] Set [Tmp School].[Fee Month] = '" & mdate & "'"
    DoCmd.OpenQuery "School Append"
    mdate = DateAdd("m", 1, mdate)
    Wend

    DoCmd.OpenQuery "Previous-Final"
    dbs.Close

    'DoCmd.OpenTable "Generated fee"
    Me.Combo15.Enabled = False
    Me.Combo19.Enabled = False
    Me.Heads_subform.Enabled = False
    MsgBox "Fee generated for the reqired Student(s)...", vbOKOnly
    End Sub
    Attached Thumbnails Attached Thumbnails GenerateForm.png   GeneratedSlip.png  

  2. #2
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    The way I handle a similar situation is by using a unique indexed field that is a concatenation of the unique ID and the other unique elements.

    So I have a table for Tasks, and a Task Log. Multiple copies of the same task can be in the task log, but only per day. So I concatenate taskID and executionDate for a unique key that says, basically, "task 17 was completed on Tuesday" (reads in the db as "17 - 5/14/2013")

  3. #3
    talktime is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    21
    Actually the database is created by someone else, he is not with us now, i don't know much about coding and the way concatenation works, if you could do something for me?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    DZ could be suggesting one of the following:

    1. a compound primary key - TaskID and ExecutionDate fields in TaskLog would both be set as primary key, Index Yes No Duplicates

    2. use code to save the TaskID and ExecutionDate as a single value in TaskLog

    I lean toward option 1.
    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.

  5. #5
    talktime is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    21
    Quote Originally Posted by June7 View Post
    DZ could be suggesting one of the following:

    1. a compound primary key - TaskID and ExecutionDate fields in TaskLog would both be set as primary key, Index Yes No Duplicates

    2. use code to save the TaskID and ExecutionDate as a single value in TaskLog

    I lean toward option 1.
    could you help me June7, i can also send you my whole database a bit larger but downloadable. plz do something, i m need

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Did you try option 1? If you set both fields as primary key then Access won't allow records that duplicate that combination. Users will get a warning popup.
    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
    talktime is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    21
    Quote Originally Posted by June7 View Post
    Did you try option 1? If you set both fields as primary key then Access won't allow records that duplicate that combination. Users will get a warning popup.
    yes i tried but in-vain, tables are related together so it will not let me create primary keys or index on compound fields

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try removing the link from the relationship builder, set primary keys, then reset the link.
    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.

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

Similar Threads

  1. Prevent duplicate records for calculated field
    By LoveLEE143 in forum Access
    Replies: 3
    Last Post: 05-03-2013, 11:46 AM
  2. Prevent duplicate dates
    By bishop0071 in forum Access
    Replies: 1
    Last Post: 01-09-2013, 09:04 PM
  3. Replies: 1
    Last Post: 01-04-2012, 01:39 PM
  4. Prevent Duplicate Entry
    By kilosierra71 in forum Forms
    Replies: 4
    Last Post: 07-28-2011, 03:08 PM
  5. Replies: 2
    Last Post: 02-12-2011, 09:54 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