can't save a record that contains '

basilyos

Registered User.
Local time
Today, 14:44
Joined
Jan 13, 2014
Messages
256
hello guys
i want to filter data this is my code
Code:
        Dim str1 As String
str1 = "[Movie_Name] LIKE '*" & Me.Movie_Name.Text & "*'"
Me![tbl_Movies_Names].Form.Filter = str1
Me![tbl_Movies_Names].Form.FilterOn = True
everything is ok but if movie_name contains ' for examples (Ender's Game) i get this error 3075
syntax error (missing operator) in query expression

i know that ' will broke the code so how can i use it
 
Last edited:
If you have ' in your string use " as delimiters.
 
uncle Gizmo Sorry the error was from filtering not from saving i edited my question sorry again

any help??
 
This is only an alternative/fyi.
Code:
str1 = "[Movie_Name] LIKE '*" & Replace(Me.Movie_Name.Text, "'", "''") & "*'"
However, I would do it the way that Uncle G and pbaldy mentioned.

By the way, why are you using the Text property? Are you running this in the Change event?
 
No problemo!

And the preferred method (as Uncle G and pbaldy suggested) is this:
Code:
str1 = "[Movie_Name] LIKE " & Chr(34) & "*" & Me.Movie_Name.Text & "*" & Chr(34)
 

Users who are viewing this thread

Back
Top Bottom