UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Converting text in tables    
 
   
Cambridgemom
post Feb 20 2004, 05:18 PM
Post #1

UtterAccess Member
Posts: 44
From: Oklahoma City



This may be a stupid question, but I inherited a database with tables imported from an old FoxPro program. All of the data is in upper case. Is there a way to convert the data within the tables to Initial Capitol case?

Thanks a million!!
Go to the top of the page
 
+
Lorraine_R
post Feb 20 2004, 05:37 PM
Post #2

UtterAccess Addict
Posts: 211
From: California



1st, make a copy of your table!!!!!!!!!!!!!!!!

Paste this into a module, then run an update query and update your field to
SetInitialCaps([fieldname])

Function SetInitialCaps(TextIn As Variant)

Dim WorkingText As String
Dim LoopCount As Integer
Dim SpaceFlag As Integer
Dim i As Integer


If IsNull(TextIn) Then GoTo SetInitialCaps_Exit

TextIn = Trim(TextIn)

If Len(TextIn) > 0 Then
WorkingText = UCase(Left(TextIn, 1))
If InStr(TextIn, " ") = 0 Then
SetInitialCaps = WorkingText & LCase(Mid(TextIn, 2))
GoTo SetInitialCaps_Exit
End If

LoopCount = Len(TextIn)
SpaceFlag = 0

For i% = 2 To LoopCount
If SpaceFlag = 0 Then
WorkingText = WorkingText & LCase(Mid(TextIn, i%, 1))
Else
WorkingText = WorkingText & UCase(Mid(TextIn, i%, 1))
End If

If Mid(TextIn, i%, 1) = " " Then
SpaceFlag = 1
Else
SpaceFlag = 0
End If
Next i%
SetInitialCaps = WorkingText
Else
SetInitialCaps = Null
End If

SetInitialCaps_Exit:
Exit Function

End Function

HTH!!!
Lorraine
Go to the top of the page
 
+
lawmart
post Feb 20 2004, 05:37 PM
Post #3

UtterAccess VIP
Posts: 2,215
From: Vermont, USA



I do not think that there is a built in function to return proper case

But here is a function that will do what you want
Paste it into a standard module and use it wherever you wish

CODE
Public Function PCase(strInput As String) As String
    Dim varArr As Variant
    Dim i As Integer
    Dim strResult As String
    
    varArr = Split(strInput)
    For i = 0 To UBound(varArr)
        strResult = strResult & " " & UCase(Left(varArr(i), 1)) & Mid(varArr(i), 2)
    Next i
    strResult = Mid(strResult, 2)
    
    PCase = strResult
    
End Function


Hope It Helps
Go to the top of the page
 
+
Lorraine_R
post Feb 20 2004, 05:43 PM
Post #4

UtterAccess Addict
Posts: 211
From: California



Be aware that it won't work on some things like
SMITH-JONES will come out Smith-jones
MCCORMICK will come out Mccormick
Go to the top of the page
 
+
Francois
post Feb 20 2004, 05:48 PM
Post #5

UtterAccess Addict
Posts: 239
From: Belgium



You can also use :
StrConv([YourField],3)
Go to the top of the page
 
+
NoahP
post Feb 20 2004, 08:43 PM
Post #6

Retired Moderator
Posts: 10,493
From: Lexington/Louisville KY USA



StrConv, as Francois pointed out, will enable you to convert a string to different 'cases'. Help in Access will provide more details.

While StrConv(YourStringHere,3) will work, I prefer StrConv(YourStringHere,vbProperCase) as it makes it easier to read.

I honestly don't use the StrConv anymore though. I know there's at least one demo/function in the Code Archive forum that can help with proper capitalisation (spelled with an S just for RCubed! (IMG:http://www.utteraccess.com/forum/style_emoticons/default/smile.gif) ).

HTH
Noah
Go to the top of the page
 
+
Francois
post Feb 21 2004, 05:06 AM
Post #7

UtterAccess Addict
Posts: 239
From: Belgium



I prefere also to use StrConv(YourStringHere,vbProperCase) if I use it in code.
But if you use it in an update query, you have to use StrConv([YourField],3).
Go to the top of the page
 
+
NoahP
post Feb 21 2004, 08:47 AM
Post #8

Retired Moderator
Posts: 10,493
From: Lexington/Louisville KY USA



Good point Francois!

(IMG:http://www.utteraccess.com/forum/style_emoticons/default/smile.gif)

Noah
Go to the top of the page
 
+
Cambridgemom
post Feb 23 2004, 05:15 PM
Post #9

UtterAccess Member
Posts: 44
From: Oklahoma City



Thanks to everyone for the code needed to change these text cases! While I have a lot of experience with Access, I am a newbie to code. I appreciate all the help!
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th June 2013 - 07:34 PM