Removing Characters with a string

G

Guest

I have an Unbound text box that searches a table for typed in records. I am
using the After Update event with the following code:
Private Sub Search_AfterUpdate()
On Error GoTo Search_AfterUpdate_Err
Me.Search = Replace(Me.Search, " ", "")
Me.Search = Replace(Me.Search, "-", "")
Me.Search = Replace(Me.Search, ".", "")

Search_AfterUpdate_Exit:
Exit Sub

Search_AfterUpdate_Err:
MsgBox Err.Description
Resume Search_AfterUpdate_Exit

End Sub

Everything works fine, but I would like to combine my three lines of code to
one line of code.

I tried using OR: Me.Search = Replace(Me.Search, " " Or "-" Or ".", "") and
got a Type Mismatch Error. What am I doing wrong or do I need to use three
separate lines of code? If I had other characters such as "," or "/" or "+",
is there some character that gets all keyboard characters other than
wildcards? Any ideas?

Thanks in advance.
 
M

Michel Walsh

Me.Search=Replace( Replace( Replace(Me.Search, " ", "" ), "-", "" ), ".",
"" )



Hoping it may help,
Vanderghast, Access MVP
 
F

fredg

I have an Unbound text box that searches a table for typed in records. I am
using the After Update event with the following code:
Private Sub Search_AfterUpdate()
On Error GoTo Search_AfterUpdate_Err
Me.Search = Replace(Me.Search, " ", "")
Me.Search = Replace(Me.Search, "-", "")
Me.Search = Replace(Me.Search, ".", "")

Search_AfterUpdate_Exit:
Exit Sub

Search_AfterUpdate_Err:
MsgBox Err.Description
Resume Search_AfterUpdate_Exit

End Sub

Everything works fine, but I would like to combine my three lines of code to
one line of code.

I tried using OR: Me.Search = Replace(Me.Search, " " Or "-" Or ".", "") and
got a Type Mismatch Error. What am I doing wrong or do I need to use three
separate lines of code? If I had other characters such as "," or "/" or "+",
is there some character that gets all keyboard characters other than
wildcards? Any ideas?

Thanks in advance.

=Replace(Replace(Replace([FieldName]," ",""),"-",""),".","")
 

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

Top