Results 1 to 3 of 3
  1. #1
    wpryan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Orlando, FL
    Posts
    5

    Preventing duplicate record

    Hi All, the database I am working on is structured as such:


    frmClinicInfo starts everything off, which contains demographic information about a customer. It contains a control to open frmProductInfo_Active

    frmProductInfo_Active contains filtered information about the customers' products. The data source is a query from tblProductInfo. This form also contains a control which opens frmProductInfo, which is the unfiltered listing of the customers' products. The data source is also tblProductInfo. Both of these forms contain a control to open frmServiceInfo.

    frmServiceInfo has a control top open frmComponents, and here is the source of my question.

    frmComponents contains information about the sub-components contained in a customer's product. There are about 20 items. If a component is replaced, then that needs to be noted in this form. In order to facilitate data entry, I put in some code which copies all data from the current record to a new one, and locks the old record. Code is here:
    Code:
    Private Sub cmdEditComponents_Click()
        DoCmd.RunCommand acCmdSelectRecord
        DoCmd.RunCommand acCmdCopy
        DoCmd.GoToRecord , , acNewRec
        DoCmd.RunCommand acCmdPasteAppend
        Me.AllowEdits = True
        If CurrentProject.AllForms("frmProductInfo_Active").IsLoaded Then
            Me.TeamviewerID = [Forms]![frmProductInfo_Active]![TeamviewerID]
            Me.MAC_Address = [Forms]![frmProductInfo_Active]![MAC_Address]
            Me.ServiceID = [Forms]![frmServiceInfo Subform]![ServiceID]
            Me.ClinicName = [Forms]![frmProductInfo_Active]![ClinicName]
            Me.FLM_Dev = [Forms]![frmProductInfo_Active]![SN]
        ElseIf CurrentProject.AllForms("frmProductInfo").IsLoaded Then
            Me.TeamviewerID = [Forms]![frmProductInfo]![TeamviewerID]
            Me.MAC_Address = [Forms]![frmProductInfo]![MAC_Address]
            Me.ServiceID = [Forms]![frmServiceInfo Subform]![ServiceID]
            Me.ClinicName = [Forms]![frmProductInfo]![ClinicName]
            Me.FLM_Dev = [Forms]![frmProductInfo]![SN]
        End If
        Me!ProductID = Forms![frmServiceInfo Subform]![ProductID]
     End Sub
    The person can then just change the one component which was exchanged. However, if a person hits the control by mistake or by just playing around, a new duplicate record will have been created. I want to prevent this from happening. I was thinking on putting some code in the After_Update event which will compare the forms' data with the previous record, and if both are equal, to not save the current record, but this is beyond my capabilities. If anyone can help me with this, or suggest another way to tackle this problem, I'd appreciate it.

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    AfterUpdate is just that -AFTER the UPDATE.
    You could try Before UPDATE. See if the record already exists eg if DCount(your test) >0 Then the record exists,
    Cancel the update and prevent a duplicate.

    Can you post a jpg of your tables and relationships? That may give readers more ideas about your set up.
    Good luck.

  3. #3
    wpryan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Orlando, FL
    Posts
    5
    Click image for larger version. 

Name:	Relationships.jpg 
Views:	12 
Size:	110.3 KB 
ID:	11749
    Thanks for your response. I've uploaded a picture of the relationships of those four tables. I guess where I want to do with the Before_Update event (thanks for your correction) is to put some If...Then code where
    if this.value1 = that.value1 and this.value2=that.value2 then
    exit form without saving
    where this = the current form and that = the previous record
    ...I hope this all makes sense!

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 Auto New Record
    By The Professor in forum Forms
    Replies: 6
    Last Post: 02-08-2013, 01:17 PM
  3. Preventing duplicate data entrry
    By FJM in forum Forms
    Replies: 4
    Last Post: 07-16-2012, 07:12 AM
  4. Replies: 1
    Last Post: 04-25-2012, 01:57 PM
  5. preventing duplicate records
    By Alliana Gray in forum Access
    Replies: 6
    Last Post: 08-11-2011, 01:18 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