Results 1 to 2 of 2
  1. #1
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87

    Resetting a form after duplicate check

    I have the below code to check for duplicate VIN's. Currently when the user clicks on Cancel, all the previously entered info is undone but the cursor stays in the VIN field. I would like to set the focus back to the Order Date field if the user clicks on Cancel but if I add OrderDate.SetFocus after the DoCmd.Save acForm, "Vehicle Order Form" line I get a Run-time error '2108', stating I must save the field before I execute the SetFocus.

    Private Sub VIN_BeforeUpdate(Cancel As Integer)
    'To check the VIN for duplicates


    If Nz(DCount("VIN", "tbl_VehicleOrders", "VIN = '" & Me.VIN.Text & "'"), 0) > 0 Then
    If MsgBox("The value you are adding already exsists, do you wish to continue?", vbOKCancel, "Duplicate Warning") = vbCancel Then
    Cancel = True
    Me.Undo
    DoCmd.Save acForm, "Vehicle Order Form"
    OrderDate.SetFocus
    Exit Sub
    End If
    End If
    End Sub

    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    DoCmd.Save does not save record, it only saves form design changes. So it really serves no purpose in your code.

    Try the textbox AfterUpdate event instead. Remove the Cancel = True line.

    Should user really have option to continue with duplicate VIN?
    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. Replies: 3
    Last Post: 04-18-2017, 02:40 AM
  2. Check For Duplicate Check Before Posting.
    By burrina in forum Queries
    Replies: 1
    Last Post: 01-22-2013, 01:39 PM
  3. How to check if there is duplicate entry
    By undee69 in forum Forms
    Replies: 8
    Last Post: 12-17-2012, 10:34 AM
  4. Resetting Record Source on Form
    By Cheshire101 in forum Programming
    Replies: 5
    Last Post: 05-05-2011, 08:52 AM
  5. check for duplicate First and Last names?
    By newtoAccess in forum Access
    Replies: 3
    Last Post: 03-19-2011, 04:05 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