sentence case

deepbreath

Registered User.
Local time
Today, 09:41
Joined
Apr 18, 2001
Messages
73
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
 
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
 
plz show me how
 
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...
Code:
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
 
Looking for "vbSentenceCase" too

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:

Code:
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
 

Users who are viewing this thread

Back
Top Bottom