Leading zero and Capitalization needed

G

Guest

I have a text field called Township in a table and on a form. It will hold
values of one number or two numbers followed by a letter of the alphabet (one
of the following letters: E, W, N, S).

After entering the data in the textbox on the form I want a leading zero to
display (and record in the table) if only one number was used and I want the
alpha character to be capitalized (form display as well as storage in the
table).
 
J

John W. Vinson

I have a text field called Township in a table and on a form. It will hold
values of one number or two numbers followed by a letter of the alphabet (one
of the following letters: E, W, N, S).

After entering the data in the textbox on the form I want a leading zero to
display (and record in the table) if only one number was used and I want the
alpha character to be capitalized (form display as well as storage in the
table).

Put the following code in the AfterUpdate event of the textbox (click on the
.... icon and choose Code Builder):

Private Sub Township_AfterUpdate()
Me.Township = UCase(Right("00" & Me.Township, 3))
End Sub

You may want to put an Input Mask such as "00A" on the textbox to force entry
of two digits and a letter; and perhaps some validation code in the control's
BeforeUpdate event to check for valid entries (I'm guessing that there is no
Twp 98W!)

John W. Vinson [MVP]
 
L

limipl

I have a text field called Township in a table and on a form. It will
hold values of one number or two numbers followed by a letter of the
alphabet (one of the following letters: E, W, N, S).

After entering the data in the textbox on the form I want a leading
zero to display (and record in the table) if only one number was used
and I want the alpha character to be capitalized (form display as well
as storage in the table).

You can do that by using len(Township.value)
and if len<>3 put a leading zero with var=0 & Township.value
and to display: Township.value=var

Put your code in the update event of Township
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top