Filter Continuous form using combo box
Posted on 2002-07-01
My simple database in Access 2002 contains a list of books, many of which have the same title but different Book_ID. I have a continuous form with all the records. In the form header I have a combo box which filters the records according to the book name. ie, If there are several books with the selected title I want them all on the form. I copied & amended the code from an example in Access Help
Private Sub cboTitleSearch_AfterUpdate()
Dim strNewRecord As String
strNewRecord = "SELECT * FROM Library " _
& " WHERE Title = '" _
& Me!cboTitleSearch.Value & "'"
Me.RecordSource = strNewRecord
Everything works fine until I select a book which has an apostrophe in the title, eg Samantha's Story
Then I get the following error:
Run-time error '3075';
Syntax error (missing operator) in query expression 'Title = 'Samantha's Story".
Can someone please help me fix it?