Errors 2448 and 3075!

C

Confused87

I have a search comand button and it works most of the time, excpet with one
name (so far) O'Shea. It comes up with the following error message:

Run- time error '2448' You can't assign a value to this object. The debugger
highlights this: Me.Filter = "[Surname] LIKE '*" & RetVal & "*'"

However othertimes, it says this:
Runt-time error '3075'
Syntax error (missing operator) in query expression "[Surname] LIKE
'*O'Shea*".

Any ideas? Here's the whole section:

Private Sub Command187_Click()
Dim RetVal As String
RetVal = InputBox("Enter Surname")

If RetVal <> "" Then
Me.Filter = "[Surname] LIKE '*" & RetVal & "*'"
Me.FilterOn = True
End If


End Sub

Many Thanks
C
 
S

Stefan Hoffmann

hi,

I have a search comand button and it works most of the time, excpet with one
name (so far) O'Shea. It comes up with the following error message:

Run- time error '2448' You can't assign a value to this object. The debugger
highlights this: Me.Filter = "[Surname] LIKE '*"& RetVal& "*'"
This is hard to solve. Is it reproduce-able?
However othertimes, it says this:
Runt-time error '3075'
Syntax error (missing operator) in query expression "[Surname] LIKE
'*O'Shea*".
This one should be obvious: You need to escape your strings. The
resulting SQL string in you case is

[Surname] LIKE '*O'

followed by the non SQL command Shea*.

Use Replace() to escape the single quotation mark.

Any ideas? Here's the whole section:
Rewrite it:

Private Sub Command187_Click()

On Local Error GoTo LocalError

Dim RetVal As String
RetVal = Trim(InputBox("Enter Surname"))

If RetVal <> "" Then
Me.Filter = "[Surname] LIKE '*" & Replace(RetVal, "'", "''") & "*'"
Me.FilterOn = True
End If

Exit Sub

LocalError:
MsgBox "Error while filtering for '" & RetVal & "'." & VbCrLf & _
Err.Number & " " & Err.Description

End Sub


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Search Button 1
Error 3075 3
Run Time Error 3075 2
Search Form Run Time Error 3075 2
Search Problem 9
Runtime Error '2448': 4
'Runtime Error 2448' 2
Run-time error 3075 3

Top