Remove blank spaces in a string

G

Guest

I have two text fields storing part numbers. One stores the stripped number
and the other stores the spaced number. Example: (12345 and 12 34 5). I
have an unbound Search text box that I currently type a stripped number into
and the record is retrieved.
DoCmd.GoToControl "[NumberID]"
DoCmd.FindRecord .Search, acEntire, False, , False, , True
DoCmd.GoToControl "Number"
I need help on the following:
If a spaced number is entered, I would like to strip all spaces and have it
find the stripped number as if I had typed the stripped number first. can
anyone help me? Thanks in advance.

hdfixitup
 
G

Guest

Hiya hd,

You should be able to use the replace function at the beginning of your
search button on_click event (assumming that's how you have it setup. In the
alternative (and maybe a better way) would be to attach this code to some
event of the textbox where you type the value (lost_focus? or
on_change?...not sure...just try and see what works). The code is simple:

Replace(txtMySearchBox, " ", "")

I think that should work.

CW
 
G

Guest

PS: The code above will work, I think, as is IF you put it in an event
associated with the text box where you enter the part number.

If you want to attach it to a search button, you'll need to do something
like this:

Me.txtMySearchBox = Replace(Me.txtMySearchBox, " ", "")

CW

Cheese_whiz said:
Hiya hd,

You should be able to use the replace function at the beginning of your
search button on_click event (assumming that's how you have it setup. In the
alternative (and maybe a better way) would be to attach this code to some
event of the textbox where you type the value (lost_focus? or
on_change?...not sure...just try and see what works). The code is simple:

Replace(txtMySearchBox, " ", "")

I think that should work.

CW

hdfixitup said:
I have two text fields storing part numbers. One stores the stripped number
and the other stores the spaced number. Example: (12345 and 12 34 5). I
have an unbound Search text box that I currently type a stripped number into
and the record is retrieved.
DoCmd.GoToControl "[NumberID]"
DoCmd.FindRecord .Search, acEntire, False, , False, , True
DoCmd.GoToControl "Number"
I need help on the following:
If a spaced number is entered, I would like to strip all spaces and have it
find the stripped number as if I had typed the stripped number first. can
anyone help me? Thanks in advance.

hdfixitup
 
G

Guest

Having decided to test it, I think I can be more accurate. You can put the
code in probably a few places, but definitely in the "lost_focus" event of
the text box itself or in the search button "on_click" event. The code
should be:

Me.txtYourPartNoInputControl = Replace(Me.txtYourPartNoInputControl, " ", "")

CW

Cheese_whiz said:
PS: The code above will work, I think, as is IF you put it in an event
associated with the text box where you enter the part number.

If you want to attach it to a search button, you'll need to do something
like this:

Me.txtMySearchBox = Replace(Me.txtMySearchBox, " ", "")

CW

Cheese_whiz said:
Hiya hd,

You should be able to use the replace function at the beginning of your
search button on_click event (assumming that's how you have it setup. In the
alternative (and maybe a better way) would be to attach this code to some
event of the textbox where you type the value (lost_focus? or
on_change?...not sure...just try and see what works). The code is simple:

Replace(txtMySearchBox, " ", "")

I think that should work.

CW

hdfixitup said:
I have two text fields storing part numbers. One stores the stripped number
and the other stores the spaced number. Example: (12345 and 12 34 5). I
have an unbound Search text box that I currently type a stripped number into
and the record is retrieved.
DoCmd.GoToControl "[NumberID]"
DoCmd.FindRecord .Search, acEntire, False, , False, , True
DoCmd.GoToControl "Number"
I need help on the following:
If a spaced number is entered, I would like to strip all spaces and have it
find the stripped number as if I had typed the stripped number first. can
anyone help me? Thanks in advance.

hdfixitup
 
G

Guest

If the part numbers are made up entirely of numbers you can prevent a user
entering anything but numeric character into the control by putting the
following in its KeyPress event procedure:

If Not IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0
End If

BTW I would advise against storing both the spaced and stripped numbers in
the table; it leaves it open to the risk of update anomalies. If you have
just the column for the stripped numbers you can always return the spaced
version with the Format function:

Format([PartNumber],"00 00 0")

If the part number can contain non-numeric characters as well as numbers you
can prevent a user entering a space with the following in the KeyPress event
procedure:

Const conSPACE = 32

If KeyAscii = conSPACE Then KeyAscii = 0

Ken Sheridan
Stafford, England
 
G

Guest

I can not express how much I appreciate your input. I replaced your txt..,
with my control name and everything worked JUST PERFECT. You ARE THE MAN!!!
Thank you again and have a great weekend.

HD

Cheese_whiz said:
Having decided to test it, I think I can be more accurate. You can put the
code in probably a few places, but definitely in the "lost_focus" event of
the text box itself or in the search button "on_click" event. The code
should be:

Me.txtYourPartNoInputControl = Replace(Me.txtYourPartNoInputControl, " ", "")

CW

Cheese_whiz said:
PS: The code above will work, I think, as is IF you put it in an event
associated with the text box where you enter the part number.

If you want to attach it to a search button, you'll need to do something
like this:

Me.txtMySearchBox = Replace(Me.txtMySearchBox, " ", "")

CW

Cheese_whiz said:
Hiya hd,

You should be able to use the replace function at the beginning of your
search button on_click event (assumming that's how you have it setup. In the
alternative (and maybe a better way) would be to attach this code to some
event of the textbox where you type the value (lost_focus? or
on_change?...not sure...just try and see what works). The code is simple:

Replace(txtMySearchBox, " ", "")

I think that should work.

CW

:

I have two text fields storing part numbers. One stores the stripped number
and the other stores the spaced number. Example: (12345 and 12 34 5). I
have an unbound Search text box that I currently type a stripped number into
and the record is retrieved.
DoCmd.GoToControl "[NumberID]"
DoCmd.FindRecord .Search, acEntire, False, , False, , True
DoCmd.GoToControl "Number"
I need help on the following:
If a spaced number is entered, I would like to strip all spaces and have it
find the stripped number as if I had typed the stripped number first. can
anyone help me? Thanks in advance.

hdfixitup
 

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