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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbProperCase 4

Status
Not open for further replies.

RachelK

Programmer
Mar 18, 2002
171
0
0
GB
Hi,

I have set my fields to vbpropercase.

I have this AfterUpdate procedure:-

Private Sub NameLong_AfterUpdate()

On Error GoTo ErrorHandler

Me.NameLong = StrConv(Me.NameLong, vbProperCase)

Exit Sub

ErrorHandler:
HandleError
Exit Sub

End Sub


The problem is sometimes the user does not want vbpropercase they would like uppercase as this would only be accosionally. I wonddered if one there was a key that they could press on the key board or something that would allow them to manually over ride or two have a button by the side of the field that would change the case to uppercase and would this trigger my after update event.

Cheers Rachel.
 
Have you thought of an option button
if OptiomButtonName =-1 then
Me.NameLong = StrConv(Me.NameLong, vbProperCase)
bla bla bla

Hope this helps
Hymn
 
Here is a ProperCase function which I use in my databases. It includes an option to leave uppercase text alone, as well as handling for names such as McDonald and O'Neill

I hope that this is useful.

Code:
Function MyProperCase(stOneLine As String, iChangeType As Integer) As String

'--------------------------------------------------------
'- This function will convert a string to Proper Case   -
'- The initial letter of each word is capitalised.      -
'- It will also handle special names such as O', Mc and -
'- hyphenated names                                     -
'- if iChangeType = 1, all text is converted to proper  -
'- case, e.g. 'FRED' is converted to 'Fred'             -
'- if iChangeType = 0, upper case text is not converted.-
'- e.g. 'fred' becomes 'Fred', but 'FRED' remains       -
'- unchanged.                                           -
'--------------------------------------------------------

Dim I As Integer
Dim bChangeFlag As Boolean
Dim stResult As String

'-----------------------------------------------------
'- No characters in string - nothing to do           -
'-----------------------------------------------------
If Len(stOneLine) = 0 Then
    MyProperCase = ""
    Exit Function
End If

'-----------------------------------------------------
'- Always set first letter to upper case             -
'-----------------------------------------------------
stResult = UCase$(Left$(stOneLine, 1))

'------------------------------------------------------
'- Now look at the rest of the string                 -
'------------------------------------------------------
For I = 2 To Len(stOneLine)
    
'-----------------------------------------------------
'- If the previous letter triggered a capital, change-
'- this letter to upper case                         -
'-----------------------------------------------------
    If bChangeFlag = True Then
        stResult = stResult & UCase$(Mid$(stOneLine, I, 1))
        bChangeFlag = False
'----------------------------------------------------------
'- In other cases change letter to lower case if required -
'----------------------------------------------------------
    Else
      If iChangeType = 1 Then
         stResult = stResult & LCase$(Mid$(stOneLine, I, 1))
      Else
         stResult = stResult & Mid$(stOneLine, I, 1)
      End If
    End If
    
'-----------------------------------------------------
'- Set change flag if a space, apostrophe or hyphen  -
'- is found                                          -
'-----------------------------------------------------
    Select Case Mid$(stOneLine, I, 1)
    Case " ", "'", "-"
        bChangeFlag = True
    Case Else
        bChangeFlag = False
    End Select
Next I

'-----------------------------------------------------
'- Special handling for Mc at start of a name        -
'-----------------------------------------------------
    If Left$(stResult, 2) = "Mc" Then
        Mid$(stResult, 3, 1) = UCase$(Mid$(stResult, 3, 1))
    End If
    
    I = InStr(stResult, " Mc")
    If I > 0 Then
        Mid$(stResult, I + 3, 1) = UCase$(Mid$(stResult, I + 3, 1))
    End If
   
MyProperCase = stResult

End Function


Bob Stubbs
 
Bob,

Thanks for your help it was just what I was looking for. So I put this in a public funtion and where do I set IChangeType to 0 also then I go to my individual fields as before and set to :-

Private Sub NameLong_AfterUpdate()

On Error GoTo ErrorHandler

Me.NameLong = StrConv(Me.NameLong, MyProperCase)

Exit Sub

ErrorHandler:
HandleError
Exit Sub

End Sub

Thanks Rachel
 
Sorry Rachel ... I should have given you an example of how to call this function, and where to put it.

First, put the function in a module in your database, so it's available anywhere in the database as required.

Here is an example of how to use it, from my database:

Code:
    Me.Surname = MyProperCase(Me.Surname, 0)

Here I am setting the text box 'Surname' using the function. The '0' after the field name in the brackets is the 'Ignore Upper case text' setting. To convert all text I would just use

Code:
    Me.Surname = MyProperCase(Me.Surname, 1)

Kind regards
Bob


Bob Stubbs
 
Bob,

Thanks it worked fantasically. You are a star! Cheers Rachel.
 
BobStubbs
nice one

Hope this helps
Hymn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top