11 replies
by syscokid
> forces an uppercase character and < forces a lowercase character, so using an input mask,
>C
by sjcbillmc
An example would be:
123 anywhere street
I would want entered as:
123 Anywhere Street
Streets names can be 3 or 4 words, each new word needs to be capitalized.
Also I think I want to use format and not input mask as I want the entereddata to be in this format not just displayed as this format.
Thanks
by donq
Without writing a rather elaborate procedure to make the first character + each character following a blank space UPPERCASE and attaching it to the After Update event what you want can't be done in Access. Then what will you do with a name like VanCamp, or McDonald???
The entire field must be formatted UPPERSASE (all characters), or lowercase (all characters). Sorry - and I have wanted this also. There are just to many exceptions when it comes to names.
by sjcbillmc
by rmrsalisbury
This is an Access function I wrote to do the job:
Public Function InitCapital(strName As String) As String
' Iterates through the given string converting all characters to lower case
' except after spaces, hyphens or apostrophes, which are made upper case
Dim flag As Boolean
Dim item As String
Dim i As Integer
flag = True
For i = 1 To Len(strName)
item = Mid(strName, i, 1)
If flag = True Then
item = UCase(item) Else
item = LCase(item)
End If
Mid(strName, i, 1) = item
Select Case item
Case " "
flag = True
Case "-"
flag = True
Case "'" flag = True
Case Else
flag = False
End Select
Next
InitCapital = strName
End Function
If you are entering data through a form you can use the field's AfterUpdate event to format the data saved to the database - but if you are entering data directly into a table datasheet you'll need to run an Update Query using the function to convert the data.
by sjcbillmc
by sl-campbell
This function will accept whatever you pass as a seperator between words and will change the next Char to Upper case.
It takes into account if the string passed starts, ends with a space or there are multiple spaces one after the other.
If you have more than one situation then you can call the function a multiple number of times, passing the next different seperator to it, or, expand on the default list and do not pass the optional character.
by sl-campbell
FUNCTION PART 1:
Public Function sCapString(ByVal sMyString As String, _
ParamArray vSepArray()) As String
Dim vSep As Variant
Dim sCurrSep As String
Dim iSepElem As Integer
Dim iSepIdx As Integer
Dim iMaxSep As Integer
Dim vStr As Variant
Dim sCurrElem As String
Dim iStrElem As Integer
Dim iMaxStr As Integer
'set working seperator array to the parameter array passed
vSep = vSepArray
'if no seperator was passed then add seperator from default list
If IsMissing(vSep) Then
'OPTION=======================================
'You can list here all possible combinations of seperators that you
'desire, which will determine what character defines that the next
'character will be uppercase. I have only listed one: a space = chr(32)
'That way you can still use the function with a specific seperator
'or, if no seperator is passed to the function, use the below list.
'Note: if no seperators are supplied and none are listed here then the original
'string is returned
'DEFAULT SEPERATOR LIST
ReDim vSep(0)
vSep(0) = Chr(32)
'=============================================
End If
'get the upperlimits of the seperator
iMaxSep = UBound(vSep)
'loop thru the seperator array
For iSepIdx = 0 To iMaxSep
'set working seperator variable to the current seperator array elementsCurrSep = vSep(iSepIdx)
'create an array for each element in the original string
'using the current seperator
vStr = Split(sMyString, sCurrSep)
'get the upperlimits of the string
iMaxStr = UBound(vStr)
by sl-campbell
FUNCTION PART 2:
'loop thru the string array
For iStrElem = 0 To iMaxStr
'set working string variable to the current string array element
sCurrElem = vStr(iStrElem)
'Check if sCurrElem is an emptystring. This can happen if an element
'of the original string(sMyString) is the same as the seperator(sSep)
'such as:
'when a double seperator, is present (if seperator is a space then Chr$(32) Chr$(32))
'the first or last Char is the seperator
If sCurrElem <> vbNullString Then
'OPTION=======================================
'Here you determine what the character is to be changed to
'Change the first Char to upper case and attach the
'remaining Characters for the current element
sCurrElem = UCase$(Left$(sCurrElem, 1)) & Right$(sCurrElem, Len(sCurrElem) - 1)
'OPTION=======================================
End If
'set the current array element to the new value
vStr(iStrElem) = sCurrElem
Next iStrElem
'Re-build the string
sMyString= Join(vStr, sCurrSep)
Next iSepIdx
'set the return vale to the new string
sCapString = sMyString
ExitProceedure:
Exit Function
ErrHandler:
'Handle error as desired - I just return the original string here.
'in case of error, return original string
sCapString = sMyString
Resume ExitProceedure
End Function
by sjcbillmc
by sjcbillmc
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending