Results 1 to 6 of 6
  1. #1
    alyon is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    89

    Question Duplicate Record

    I had a duplicate button on my form that worked perfect..

    Private Sub cmdDuplicate_Click()


    Dim Inspection As Integer
    Inspection = Me.txtInspection.Value

    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.RunCommand acCmdPasteAppend

    Me.txtInspection.Value = DMax("[Inspection #]", "[Enter Inspection]") + 1
    Exit_CopyRecord:
    Exit Sub
    End Sub


    However, I added a combobox search

    Private Sub cboNumberSearch_AfterUpdate()
    Me.Filter = "[Inspection #]= " & cboNumberSearch
    Me.FilterOn = True
    End Sub

    And my duplicate button no longer works. It comes up with an error that says my primary key is being duplicated. However the primary key is NOT the inspection # you see listed above, though that will no longer add +1.

    Any suggestions?

    If you need any clarification, please ask.. I understand this post was confusing!

    Thanks in advance for the help!
    alyon

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Are you using a bound form, you must be if you're having a duplicate issue.

    if you are when you do this:

    Me.txtInspection.Value = DMax("[Inspection #]", "[Enter Inspection]") + 1

    and the field txtinspection is your PK you are generating a new record by populating it but you won't get an error message until you try to navigate away from that record (for instance when you click your number search button)

    You will likely have to issue an undo command before you can use your search function if you intend to use a filter instead of basing your form on a query.

  3. #3
    alyon is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    89
    Yes, I am using a bound form, but the field txtinspections is not my primary key. I get an error immediately after clicking the button, without searching, as well as when I try to navigate away from that record (it's the same error complaining about the primary key). I have to use a filter for the combobox rather than a query (it was requested I do so). Since the original error happens before I try to navigate away, would an undo command in my search function still help?

  4. #4
    alyon is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    89
    Well, I got it to work by using

    IsNull (cboNumberSearch)
    Me.FilterOn = False

    in my duplicate button code.

    Thanks for all your help!
    alyon

  5. #5
    alyon is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    89
    However, I'm still having problems with another search combobox which is stopping the duplicate button.

    Private Sub cboContractorSearch_AfterUpdate()
    Dim strFilter As String
    strFilter = strFilter & "([Contractor Name] Like '*" & Me.cboContractorSearch & "*')"
    Me.Filter = strFilter
    Me.FilterOn = True
    End Sub

    I'm assuming because of the like part of the filter, I can't seem to get the filter turned off, I used Me.FilterOn = False and it wouldn't work. Any suggestions are greatly appreciated!

    Thanks

  6. #6
    alyon is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    89
    If anyone else is having the above problem I had, I got around it.
    I used a simple copy from current record and paste to new record method for the textboxes I needed duplicated.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-09-2013, 10:39 AM
  2. Goto Record when Duplicate Record Exists
    By rlsublime in forum Programming
    Replies: 13
    Last Post: 03-22-2012, 03:46 PM
  3. Replies: 5
    Last Post: 03-02-2012, 08:58 PM
  4. Duplicate last record to next record in form
    By jdhaldane in forum Forms
    Replies: 4
    Last Post: 12-17-2010, 04:22 PM
  5. If duplicate record, go to original record
    By BigBear in forum Forms
    Replies: 2
    Last Post: 10-06-2010, 02:58 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