Help !

Y

Yaar75

Novice to Access, so apologies for daft question

I need to clean up the record.

address quoted with house number ie

25 Connaught Street
253 Ellis Road
154/A Garner Road
1 Field Avenue

I want to seperate house number and street name.

Query number 2, I have phone number but have "-" in it , ie

020-8428-428

wish to remove "-" and read number as 0208 428428 as etc.

please help !!!! Thanks
 
J

John W. Vinson

Novice to Access, so apologies for daft question

I need to clean up the record.

address quoted with house number ie

25 Connaught Street
253 Ellis Road
154/A Garner Road
1 Field Avenue

I want to seperate house number and street name.

You can get *most* of the instances using an expression like:

HouseNumber: Left([address], InStr([address], " ") - 1)
Street: Trim(Mid([address], InStr([address], " "))

The exceptions will be addresses like

1412 1/2 S. Zenith
224 B Baker St.

with a blank in what you consider to be the house number. You'll need to look
over the results to find these.
Query number 2, I have phone number but have "-" in it , ie

020-8428-428

wish to remove "-" and read number as 0208 428428 as etc.

Run an Update query, probably in two steps. First update the Phone field to

Replace([Phone], "-", "")

to remove the hyphens; then (if you want to insert the blank in every record)
update it to

Left([Phone], 4) & " " & Mid([Phone], 5)
 
Y

Yaar75

John said:
Novice to Access, so apologies for daft question
[quoted text clipped - 8 lines]
I want to seperate house number and street name.

You can get *most* of the instances using an expression like:

HouseNumber: Left([address], InStr([address], " ") - 1)
Street: Trim(Mid([address], InStr([address], " "))

The exceptions will be addresses like

1412 1/2 S. Zenith
224 B Baker St.

with a blank in what you consider to be the house number. You'll need to look
over the results to find these.
Query number 2, I have phone number but have "-" in it , ie

020-8428-428

wish to remove "-" and read number as 0208 428428 as etc.

Run an Update query, probably in two steps. First update the Phone field to

Replace([Phone], "-", "")

to remove the hyphens; then (if you want to insert the blank in every record)
update it to

Left([Phone], 4) & " " & Mid([Phone], 5)

John (Legend !!)

Many thanks for swift update.

However, phone field not working, it my mistake, I forgot to mention, I am
working on Access 97 due to old record.

So I believe replace function may not be available. Any thoughts !!!

Thanking you in anticipation
 
J

John W. Vinson

However, phone field not working, it my mistake, I forgot to mention, I am
working on Access 97 due to old record.

So I believe replace function may not be available. Any thoughts !!!

Create a new Module (or include this sub in an existing module):

Public Function MyReplace(strIn As String, _
strOld As String, strNew As String) As String
MyReplace = Replace(strIn, strOld, strNew)
End Function

Then use MyReplace in your query instead of Replace.

A97 has a Replace function - it just must be called from VBA not from queries,
an oversight corrected in later versions.
 
J

John Spencer

John,
Pardon me. But I seem to recall that Replace was not added until Access 2000.
Before that you needed to use a custom VBA function. Here is one from my
archives.

'Courtesy of John Viescas
Public Function Replace(strIn As Variant, strFind As String, _
strReplace As String, Optional intStart As Integer = 1, _
Optional intCount As Integer = -1, _
Optional intCompare As Integer = 0) As String
'-----------------------------------------------------------
' Inputs: String to search and replace,
' search string, replacement string,
' optional starting position (default = 1),
' optional replacement limit (default = -1 .. ALL)
' optional string compare value (default = 0 .. vbBinaryCompare)
' Outputs: Replaced string
' Created By: JLV 09/05/01
' Last Revised: JLV 09/05/01
' ** Duplicates the functionality of the VB 6 REPLACE function.
'-----------------------------------------------------------
Dim strWork As String, intS As Integer, intCnt As Integer
Dim intI As Integer, intLenF As Integer, intLenR As Integer

If (intCompare < 0) Or (intCompare > 2) Then
Err.Raise 5
Exit Function
End If
If VarType(strIn) <> vbString Then
Err.Raise 5
Exit Function
End If
strWork = strIn
intS = intStart
intCnt = intCount
intLenF = Len(strFind)
intLenR = Len(strReplace)
' If find string zero length or count is zero, then nothing to replace
If (intLenF = 0) Or (intCnt = 0) Then
Replace = strIn
Exit Function
End If
' If start beyond length of string, return empty string
If intS > Len(strWork) Then
Replace = ""
Exit Function
End If

' Got some work to do -- find strings to replace
Do
intI = InStr(intS, strWork, strFind, intCompare)
If intI = 0 Then Exit Do
' Insert the replace string
strWork = Left(strWork, intI - 1) & _
strReplace & Mid(strWork, intI + intLenF)
'Bump start to end of the replace string
intS = intS + intI + intLenR - 1
intCnt = intCnt - 1 ' Decrement the max replace counter
Loop Until intCnt = 0
Replace = strWork

End Function


--
John Viescas, author
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
Y

Yaar75 via AccessMonster.com

Thank you John & John

I have successfully manage to remove Alpha from Numeric field, and now only
stuck at last stage

02085473428

I want phone number display as 0208 5473428

Left and Mid function do not appear to have worked, it missed some digit in
the end.

guys, you have been really great, could you kindly assist me to get this
right, so I will be home and dry........Thanking you in anticipation.

John Spencer, i am newbie, so love to understand ur vba coding in details. as
what does each part do !!!!

John said:
John,
Pardon me. But I seem to recall that Replace was not added until Access 2000.
Before that you needed to use a custom VBA function. Here is one from my
archives.

'Courtesy of John Viescas
Public Function Replace(strIn As Variant, strFind As String, _
strReplace As String, Optional intStart As Integer = 1, _
Optional intCount As Integer = -1, _
Optional intCompare As Integer = 0) As String
'-----------------------------------------------------------
' Inputs: String to search and replace,
' search string, replacement string,
' optional starting position (default = 1),
' optional replacement limit (default = -1 .. ALL)
' optional string compare value (default = 0 .. vbBinaryCompare)
' Outputs: Replaced string
' Created By: JLV 09/05/01
' Last Revised: JLV 09/05/01
' ** Duplicates the functionality of the VB 6 REPLACE function.
'-----------------------------------------------------------
Dim strWork As String, intS As Integer, intCnt As Integer
Dim intI As Integer, intLenF As Integer, intLenR As Integer

If (intCompare < 0) Or (intCompare > 2) Then
Err.Raise 5
Exit Function
End If
If VarType(strIn) <> vbString Then
Err.Raise 5
Exit Function
End If
strWork = strIn
intS = intStart
intCnt = intCount
intLenF = Len(strFind)
intLenR = Len(strReplace)
' If find string zero length or count is zero, then nothing to replace
If (intLenF = 0) Or (intCnt = 0) Then
Replace = strIn
Exit Function
End If
' If start beyond length of string, return empty string
If intS > Len(strWork) Then
Replace = ""
Exit Function
End If

' Got some work to do -- find strings to replace
Do
intI = InStr(intS, strWork, strFind, intCompare)
If intI = 0 Then Exit Do
' Insert the replace string
strWork = Left(strWork, intI - 1) & _
strReplace & Mid(strWork, intI + intLenF)
'Bump start to end of the replace string
intS = intS + intI + intLenR - 1
intCnt = intCnt - 1 ' Decrement the max replace counter
Loop Until intCnt = 0
Replace = strWork

End Function

--
John Viescas, author
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
[quoted text clipped - 12 lines]
A97 has a Replace function - it just must be called from VBA not from queries,
an oversight corrected in later versions.
 
J

John Spencer

If you want it to display that way then use a format mask.
Format("02085473428","0000 0000000") will display 0208 5473428
The stored value will still be 02085473428

If you need to change the way it is stored you will need an UPDATE query.

John Spencer
Access MVP 2002-2005, 2007-2010

The Hilltop Institute
University of Maryland Baltimore County
Thank you John & John

I have successfully manage to remove Alpha from Numeric field, and now only
stuck at last stage

02085473428

I want phone number display as 0208 5473428

Left and Mid function do not appear to have worked, it missed some digit in
the end.

guys, you have been really great, could you kindly assist me to get this
right, so I will be home and dry........Thanking you in anticipation.

John Spencer, i am newbie, so love to understand ur vba coding in details. as
what does each part do !!!!

John said:
John,
Pardon me. But I seem to recall that Replace was not added until Access 2000.
Before that you needed to use a custom VBA function. Here is one from my
archives.

'Courtesy of John Viescas
Public Function Replace(strIn As Variant, strFind As String, _
strReplace As String, Optional intStart As Integer = 1, _
Optional intCount As Integer = -1, _
Optional intCompare As Integer = 0) As String
'-----------------------------------------------------------
' Inputs: String to search and replace,
' search string, replacement string,
' optional starting position (default = 1),
' optional replacement limit (default = -1 .. ALL)
' optional string compare value (default = 0 .. vbBinaryCompare)
' Outputs: Replaced string
' Created By: JLV 09/05/01
' Last Revised: JLV 09/05/01
' ** Duplicates the functionality of the VB 6 REPLACE function.
'-----------------------------------------------------------
Dim strWork As String, intS As Integer, intCnt As Integer
Dim intI As Integer, intLenF As Integer, intLenR As Integer

If (intCompare < 0) Or (intCompare > 2) Then
Err.Raise 5
Exit Function
End If
If VarType(strIn) <> vbString Then
Err.Raise 5
Exit Function
End If
strWork = strIn
intS = intStart
intCnt = intCount
intLenF = Len(strFind)
intLenR = Len(strReplace)
' If find string zero length or count is zero, then nothing to replace
If (intLenF = 0) Or (intCnt = 0) Then
Replace = strIn
Exit Function
End If
' If start beyond length of string, return empty string
If intS > Len(strWork) Then
Replace = ""
Exit Function
End If

' Got some work to do -- find strings to replace
Do
intI = InStr(intS, strWork, strFind, intCompare)
If intI = 0 Then Exit Do
' Insert the replace string
strWork = Left(strWork, intI - 1) & _
strReplace & Mid(strWork, intI + intLenF)
'Bump start to end of the replace string
intS = intS + intI + intLenR - 1
intCnt = intCnt - 1 ' Decrement the max replace counter
Loop Until intCnt = 0
Replace = strWork

End Function

--
John Viescas, author
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
However, phone field not working, it my mistake, I forgot to mention, I am
working on Access 97 due to old record.
[quoted text clipped - 12 lines]
A97 has a Replace function - it just must be called from VBA not from queries,
an oversight corrected in later versions.
 
J

John W. Vinson

Thank you John & John

I have successfully manage to remove Alpha from Numeric field, and now only
stuck at last stage

02085473428

I want phone number display as 0208 5473428

Are you using a *NUMBER* datatype here? If so, DON'T. Number fields don't
contain blanks or text, don't have leading zeroes, are limited to ten digits
(two billion odd is the largest possible Long Integer)...

Phone numbers aren't "numbers" in the sense that you'll never do arithmatic
with them. The average of your contacts' phone numbers is simply not a useful
piece of information! Use a text field instead. The Left and Mid functions
will work correctly - *on a Text field*.
 
Y

Yaar75 via AccessMonster.com

John/John

Many thanks for your assistance, I did it slightly long winded, changed text
and than identified the length than used left and right function to seperate
and concatenate.

I have to present data tomorrow morning......but you both have been most
usedful, thanks.

No doubt, I will back on this site to pick your brain again, so bear with me.


regards
Thank you John & John
[quoted text clipped - 4 lines]
I want phone number display as 0208 5473428

Are you using a *NUMBER* datatype here? If so, DON'T. Number fields don't
contain blanks or text, don't have leading zeroes, are limited to ten digits
(two billion odd is the largest possible Long Integer)...

Phone numbers aren't "numbers" in the sense that you'll never do arithmatic
with them. The average of your contacts' phone numbers is simply not a useful
piece of information! Use a text field instead. The Left and Mid functions
will work correctly - *on a Text field*.
 

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