Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Substring Replace 2

Status
Not open for further replies.

chrislx

Programmer
Oct 17, 2003
32
US
I need to change the string, such as "it is an access form" , into "ItIsAnAccessForm". Remove the space and display upper cass for the first char of each word. The following code remove the space, but cannot change from lower case to upper case. does anyone has good idea for the case change. Thanks.

Sub SubStringReplace()
Dim iPos As Integer
Dim iStart As Integer
Dim str As String
Dim chr As String
Dim temp As String
str = "it is an Access Form
chr$ = " "

iStart% = 1
Do
'Find beginning position
iPos% = InStr(iStart%, str$, chr$)

'If not there, then get out
If iPos% = 0 Then Exit Do

'Combine left and right portion

str$ = Left(str$, iPos% - 1) & Right(str$, Len(str$) - iPos% - Len(chr$) + 1)

'MsgBox str$
'Calculate where to begin next search
iStart% = iPos%
Loop
end Sub


 
From version 2000, you should be able to:

[tt]strMyString = "it is an Access Form"
strNewString=replace(strconv(strMyString,vbpropercase)," ","")[/tt]

- str and chr are a functions, and should be avoided as variable names

Roy-Vidar
 
For old version of access, you can try something like this:
myString = UCase(Left(myString, 1)) & Mid(myString, 2)
i = 1
Do
i = InStr(i, myString, " ")
If i = 0 Then Exit Do
myString = Left(myString, i - 1) _
& UCase(Mid(myString, i + 1, 1)) _
& Mid(myString, i + 2)
Loop

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top