Link to home
Start Free TrialLog in
Avatar of Doozy
Doozy

asked on

Filter Continuous form using combo box

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
End Sub

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?
Thanks

ASKER CERTIFIED SOLUTION
Avatar of TextReport
TextReport
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Doozy
Doozy

ASKER

Works a dream - Thanks so much