My form is called fItems that is based on a table called Items.
A text box named iTitle is added to fItems. To avoid duplication of a title I added the following codes as an After_Update for iTitle. It's working with one problem. If I have an apostrophe in a title I get an error message:
Run Time Error '3075': Syntax error (missing operator) in query expression '[iTitle] = "Who's Coming to Dinner"
Can someone please help me correct this coding? Many thanks.
A text box named iTitle is added to fItems. To avoid duplication of a title I added the following codes as an After_Update for iTitle. It's working with one problem. If I have an apostrophe in a title I get an error message:
Run Time Error '3075': Syntax error (missing operator) in query expression '[iTitle] = "Who's Coming to Dinner"
Code:
Private Sub iTitle_AfterUpdate() Dim iTitle As String Dim stLinkCriteria As String Dim rsc As DAO.Recordset Set rsc = Me.RecordsetClone iTitle = Me.iTitle.Value stLinkCriteria = "[iTitle]=" & "'" & [iTitle] & "'" 'Check Items table for duplicate iTitle If DCount("iTitle", "Items", _ stLinkCriteria) > 0 Then 'Undo duplicate entry Me.Undo 'Message box warning of duplication MsgBox "Warning Item Title " _ & iTitle & " has already been entered." _ & vbCr & vbCr & "You will now been taken to the record.", _ vbInformation, "Duplicate Information" 'Go to record of original Title rsc.FindFirst stLinkCriteria Me.Bookmark = rsc.Bookmark End If Set rsc = Nothing End Sub
Comment