Results 1 to 3 of 3
  1. #1
    Wesant is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2011
    Posts
    2

    Prevent suspected duplicate records in form

    Hi,
    I got this very simple order form, used by several people. Often unknowingly they would place an duplicate order for the same company. I would like to capture this before record is saved and give the operator option to cancel, add or view suspected duplicate. I managed to do that, but only with single parameter. How do I add second parameter that would check for orders done in last seven days from date of current order and alert the operator? I manage to find bits and pieces of code and had help from others, see code below, but this is limit of my capabilities.



    I am getting Run-time error 3075:
    Syntax error (missing operator) in query expression
    'PhName="PRICELINE GOULBURN" AND OrderDate Between 5/02/2011 9:16.31 PM AND #12/02/2011 9:16:31 PM#

    Table name - PBSOrder_tbl
    Table field - OrderDate
    Form control name - OrderDate

    OrderDate is recorded as Date/Time with default value Now() to record date and time of order to capture orders placed the same day by different operator for the same company.

    Here is the complete code:

    Dim SID As String
    Dim stLinkCriteria As String
    Dim iAns As Integer
    Dim rsc As DAO.Recordset
    Set rsc = Me.RecordsetClone
    SID = Me.PhName.Value
    stLinkCriteria = "PhName=" & Chr(34) & SID & Chr(34) & " AND OrderDate Between " & DateAdd("d", -7, Me.OrderDate) & " AND #" & Me.OrderDate & "#"
    If DCount("*", "PBSOrder_tbl", stLinkCriteria) > 0 Then
    iAns = MsgBox("This job already exists! Add it anyway?" _
    & vbCrLf & "Click Yes to add, No to jump to existing record, " _
    & vbCrLf & "Cancel to go back to editing this record", _
    vbYesNoCancel)
    Select Case iAns
    Case vbYes ' do nothing, let the record be added
    Set rsc = Nothing
    If MsgBox("You are about to add an order." _
    & vbCrLf & vbCrLf & "Do you want to save this order?" _
    , vbYesNo, "Order confirmation") = vbYes Then
    DoCmd.Save
    Else
    DoCmd.RunCommand acCmdUndo
    End If
    Case vbNo
    Cancel = True
    Me.Undo
    rsc.FindLast stLinkCriteria
    Me.Bookmark = rsc.Bookmark ' move to last found record
    Case vbCancel
    Cancel = True ' suppress update, return to form
    End Select
    End If
    ================================================== ====
    I will appreciate anyones assistance.

    Regards

    Wesley

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    As answered elsewhere, you correctly surrounded the second date/time value with #, but didn't with the first.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Wesant is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2011
    Posts
    2

    Unhappy

    Quote Originally Posted by pbaldy View Post
    As answered elsewhere, you correctly surrounded the second date/time value with #, but didn't with the first.
    Thanks Paul ,

    Sorry for duplicate post, but I can't get anywhere with my problem.

    I did that, see below:

    stLinkCriteria = "PhName=" & Chr(34) & SID & Chr(34) & " AND OrderDate BETWEEN #" & DateAdd("d", -7, Me.OrderDate) & "# AND #" & Me.OrderDate & "#"

    Ok, using your method of debugging, I found out that the string is working correctly, but for some reason does not trigger the action prompt if the record is found. Please see code in my original post.

    It will prompt for action if I try to amend an existing record within seven days range. I got no Idea why.

    Can you or anyone else please help?

    Regards

    Wesley
    Last edited by Wesant; 02-13-2011 at 12:20 AM.

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

Similar Threads

  1. Replies: 4
    Last Post: 12-13-2010, 05:33 PM
  2. Prevent Users from Deleting Records
    By DocOrganizer in forum Access
    Replies: 15
    Last Post: 11-30-2010, 02:57 PM
  3. Prevent a form from closing
    By ksmithson in forum Forms
    Replies: 0
    Last Post: 07-15-2010, 12:49 PM
  4. Replies: 1
    Last Post: 06-25-2010, 09:56 AM
  5. Prevent Duplicate Values on Combination of Two Fields
    By LornaM in forum Database Design
    Replies: 8
    Last Post: 05-05-2009, 11:16 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