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.