How do I insert Parentheses automatically into a field in Access?

S

SonnyBobSue

I am creating a new data base and want to know how to have what I type into a
particular field automatically have parentheses around it - or is that
possible?
 
S

Steve Schapel

SonnyBobSue,

Yes. One way to do it would be to put code on the After Update event of the
textbox on the form where you enter data into this field. Something like
this:

Me.NameOfField = "(" & Me.NameOfField & ")"

However, if there is a chance you will be subsequently editing this data,
you may want to cover that off so you don't get multiple parentheses, one
set for every time you enter/edit the data.

If Me.NameOfField Like "(*" Then
' already has parentheses
Else
Me.NameOfField = "(" & Me.NameOfField & ")"
End If
 
J

Jeanette Cunningham

Hi SonnyBobSue,
it's not clear where you are typing - into a text box on a form? or are you
creating a table in design view?

If into a text box on a form, you can use the after update event of the
textbox.

Me.NameOfTextBox = "(" & Me.NameOfTextBox & ")"

Replace NameOfTextBox with the name of the control.

One difficulty is that the parentheses may already be there because the user
is editing the contents of the textbox.
You could get your code to check for that. If the textbox is a bound control
(has a control source), you could do something like this:

If Left$(Me.NameOfTextBox,1) = "(" Then
Else
Me.NameOfTextBox = "(" & Me.NameOfTextBox & ")"
End If

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

John W. Vinson

I am creating a new data base and want to know how to have what I type into a
particular field automatically have parentheses around it - or is that
possible?

Why?

What's the context? What purpose do these parentheses serve? Is this a Text
field, or a Number? If a number, do the parentheses mean that it's a negative
number?

If you just want to *DISPLAY* parentheses, on a form or report, without
wasting two bytes in every record, you can use the Format property of the
field.
 
A

Andrew Dilbeck

SonnyBobSue said:
I am creating a new data base and want to know how to have what I type into
a
particular field automatically have parentheses around it - or is that
possible? no
 

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