View Full Version : sentence case


deepbreath
06-11-2001, 04:29 AM
i have a memo field which i want to convert to sentece case after update. i know strconv is there but not sure how to do this. this i need to do in form, table and in report
thankx

KDg
06-11-2001, 04:50 AM
Hi db,

i don't think you're going to be able to do this with StrConv. You'll probably need to read the value of the field ( changing the first letter to UCASE ) and then hunt out ( instr() ) each . ( chr(46) ). Once you've found that '. ' read the following characters, as soon as you get to one that's not a space ( chr(32) ) change it to a capital and keep moving ( instr() )...

HTH

Drew

deepbreath
06-11-2001, 09:21 AM
plz show me how

KDg
06-12-2001, 08:01 AM
hi db,

I've run the below and it seems to work okay - gets a bit slower on big memos ( ran it for 15,000 chars and had to wait a bit... ).

I guess you may be able get it to go quicker if you just moved the data into another box or play about with strings, but this does at least work...

Dim x As Integer
Dim y As Integer
Dim lngLenMem As Long

lngLenMem = Len(Me.txtMemo)
'little loop to Cap first letter

x = 1
Do Until StrComp(Mid(Me.txtMemo, x, 1), Chr(32)) <> 0
x = x + 1
Loop
Me.txtMemo = Left(Me.txtMemo, x - 1) & UCase(Mid(Me.txtMemo, x, 1)) & Right(Me.txtMemo, lngLenMem - x)


On Error GoTo Oops
Do While x < lngLenMem
If InStr(x, Me.txtMemo, ".") Then
x = InStr(x, Me.txtMemo, ".")
y = 1
Do Until StrComp(Mid(Me.txtMemo, x + y, 1), Chr(32)) <> 0
y = y + 1
Loop
Me.txtMemo = Left(Me.txtMemo, x + y - 1) & UCase(Mid(Me.txtMemo, x + y, 1)) & Right(Me.txtMemo, lngLenMem - x - y)
End If
y = 0
x = x + 1
Loop

Oops:
'probably the end of the memo field causing and error, time to forget it
End Sub


Any probs post back,

HTH

Drew

RossWindows
04-16-2008, 10:37 AM
I was looking for a script that would essentially make a field use "vbSentenceCase"

I came across your script which worked wonderfully with some slight modifications for Access 97.

Here is the code that worked for me:

Private Sub Other_Info_AfterUpdate()
On Error GoTo Exit_Other_Info_After_Update

Dim x, y As Integer, vbSentenceCase As Long

vbSentenceCase = Len(Me![Other Info])

x = 1
Do Until StrComp(Mid(Me![Other Info], x, 1), Chr(32)) <> 0
x = x + 1
Loop
Me![Other Info] = Left(Me![Other Info], x - 1) & UCase(Mid(Me![Other Info], x, 1)) & Right(Me![Other Info], vbSentenceCase - x)

Do While x > vbSentenceCase
If InStr(x, Me![Other Info], ".") Then
x = InStr(x, Me![Other Info], ".")
y = 1
Do Until StrComp(Mid(Me![Other Info], x + y, 1), Chr(32)) <> 0
y = y + 1
Loop
Me![Other Info] = Left(Me![Other Info], x + y - 1) & UCase(Mid(Me![Other Info], x + y, 1)) & Right(Me![Other Info], vbSentenceCase - x - y)
End If
y = 0
x = x + 1
Loop

Exit_Other_Info_After_Update:

End Sub