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

Formatting of fields 1

Status
Not open for further replies.

gingerboy

Technical User
Jul 22, 2003
7
GB
Is there a function whereby i can capitalise the initial letter of each word in a field. I have managed to get Access to capitalise the whole field with '>', and using input masks, i've managed to have the first letter of the field capitalised, but i want each word to be capitalised (it is a name filed with first and last names)

Cheers
 
Hi,

You need to use the strConv function:

Code:
myString = strConv (myString, vbProperCase)

Andrew
 
How do i use this code? Will it force the capitalisation in the stored record, or does it only format the text in a form?

Cheers
 
Hi,

It will just format the text in the form, but you could easily write a function to update the fields in the database.

Code:
dim l_str_sql as string
dim l_rec_set as recordset
dim l_counter as Integer

l_str_sql = "SELECT myKey, myField FROM myTable"
set l_rec_set = currentDb.openrecordset (l_str_sql)

l_rec_set.moveLast
l_rec_set.moveFirst

for l_counter = 1 to l_rec_set.recordCount
    l_str_sql = "UPDATE myTable SET myField = '" & strConv (l_rec_set.Fields![myField], vbProperCase) & "'"
    l_str_sql = l_str_sql & "WHERE myKey = " & l_rec_set.Fields![myKey]
     currentdb.execute l_str_sql
next l_counter

If you wanted to do it on a form:

Code:
me.myText = strConv (me.myText, vbProperCase

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top