I have created a search field on a form that refers to a query. It searches by Organization Name. Some organizations have an apostrophe in the name, and that caused an error No. 3077. This was remedied with the following code:
Now I am able to perform the search and have the form autofill after a selection.
My problem is that I then changed gave that field an index of "Yes (No Duplicates)". After I did that, my search still works, UNLESS I SELECT AN ORGANIZATION WITH AN APOSTROPHE in the name. It works if it is not indexed, but not if it is indexed. I need the field to be indexed, no duplicates, but also need the search field to work. Any suggestions?
Code:
Public Function fHandleApostrophe(strPass As String) As String Dim strRet As String strRet = strPass If InStr(1, strRet, "'", vbTextCompare) > 0 Then strRet = "'" & Replace(strRet, "'", "''", , , vbTextCompare) & "'" Else strRet = "'" & strRet & "'" End If fHandleApostrophe = strRet End Function
Code:
Sub cmbOrgName_AfterUpdate() ' Find the record that matches the control. Me.RecordsetClone.FindFirst "[OrganizationName]= " & fHandleApostrophe(Me![cmbOrgName]) Me.Bookmark = Me.RecordsetClone.Bookmark End Sub
My problem is that I then changed gave that field an index of "Yes (No Duplicates)". After I did that, my search still works, UNLESS I SELECT AN ORGANIZATION WITH AN APOSTROPHE in the name. It works if it is not indexed, but not if it is indexed. I need the field to be indexed, no duplicates, but also need the search field to work. Any suggestions?
Comment