formatting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I am trying to set up a code so that when values are entered in a form
they are displayed with capital letters at the start of each word for example
a name entered john smith would be viewed as John Smith.

Somebody very kindly sent me the following code to use afterupdate event but
as I am very new to access I am not really sure how to use this can anyone
help?

[FieldName] =strConv([FieldName],3)
 
Hi I am trying to set up a code so that when values are entered in a form
they are displayed with capital letters at the start of each word for example
a name entered john smith would be viewed as John Smith.

Somebody very kindly sent me the following code to use afterupdate event but
as I am very new to access I am not really sure how to use this can anyone
help?

[FieldName] =strConv([FieldName],3)

Open the form in design view. I'd actually suggest changing the code
just a little bit to allow for names like MacDonald or McClure to be
entered without having Access change to Macdonald or Mcclure.

Click on the ... icon by the AfterUpdate event of the form textbox and
choose Code Builder. Let's say the name of the textbox is txtLastName
(btw: you should certainly store first and last names in different
fields, so you can easily sort or search by either name). Access will
automatically give you the first and last lines of the following; just
edit what's in between:

Private Sub txtLastName_AfterUpdate()
' Check to see if the name was entered in all lower case
' If so, convert it to Proper Case; if not, leave it alone
If StrComp(Me!txtLastName, LCase(Me!txtLastName), 0) = 0 Then
Me!txtLastName = StrConv(Me!txtLastName, vbProperCase)
End If
End Sub


John W. Vinson[MVP]
 
Hi John

Thats great really helpful thanks, I have input that but it seems to change
the whole field to uppercase, any ideas on what I have done wrong??

Also just out of interest for future reference what function does the me bit
have in the code?

John Vinson said:
Hi I am trying to set up a code so that when values are entered in a form
they are displayed with capital letters at the start of each word for example
a name entered john smith would be viewed as John Smith.

Somebody very kindly sent me the following code to use afterupdate event but
as I am very new to access I am not really sure how to use this can anyone
help?

[FieldName] =strConv([FieldName],3)

Open the form in design view. I'd actually suggest changing the code
just a little bit to allow for names like MacDonald or McClure to be
entered without having Access change to Macdonald or Mcclure.

Click on the ... icon by the AfterUpdate event of the form textbox and
choose Code Builder. Let's say the name of the textbox is txtLastName
(btw: you should certainly store first and last names in different
fields, so you can easily sort or search by either name). Access will
automatically give you the first and last lines of the following; just
edit what's in between:

Private Sub txtLastName_AfterUpdate()
' Check to see if the name was entered in all lower case
' If so, convert it to Proper Case; if not, leave it alone
If StrComp(Me!txtLastName, LCase(Me!txtLastName), 0) = 0 Then
Me!txtLastName = StrConv(Me!txtLastName, vbProperCase)
End If
End Sub


John W. Vinson[MVP]
 
Hi John

Thats great really helpful thanks, I have input that but it seems to change
the whole field to uppercase, any ideas on what I have done wrong??

Please post your actual code. Sounds like you may have used
vbUpperCase (2) instead of vbProperCase (3) as the argument.
Also just out of interest for future reference what function does the me bit
have in the code?

Me. or Me! is shortcut language for "the name of the form that this
code is on"; it lets you refer to a control on the current form, in a
way that takes less typing and is portable from form to form.

John W. Vinson[MVP]
 
Back
Top