Add a + to Country Code field

M

MikeF

Access 2007, have a text field called CountryCode.

In its form field, would like to add a "+" character in front of it.

Tried ="+"&CountryCode, ie excel, but doesn't work.

Any assistance will be greatly appreciated.

Thanx,
-Mike
 
P

PJFry

Can you be a bit more specific on what you tired? Did you set the control
source to be "+"&CountryCode?

Is the CountryCode field a field that someone will edit, or is it just there
for informational purposes? Is it a stand alone field, or is it part of
another field, like part of the phone number?

Assuming it is a standalone field, will your the CountryCode always contain
the "+"? If so, consider converting that field to a text field. My personal
rule is that unless I am going to be performing calculations, I make things
like area codes, zip codes, etc as text. At the end of the day it makes them
easier to handle.

Let me know and we can get this solved for you.
 
L

Linq Adams via AccessMonster.com

It is a text field, per the original post.

This code will do the job. You have to be careful, when using the ampersand,
to leave a space between the components you're stringing together:

Private Sub CountryCode_AfterUpdate()
If Not IsNull(Me.CountryCode) Then
Me.CountryCode = "+" & Me.CountryCode
End If
End Sub
 
M

MikeF

It is a standalone text field.
But contains only phone country code numbers, that's it.
Only want to automatically add a + to the beginning of each number in the
form, not the table.
Nobody will edit it, but it may become part of a concantenated phone number
sequence at some point.
Did you set the control source to be "+"&CountryCode?
Yes, but that doesn't work.

Thank you.
- Mike
 
P

PJFry

Very good.

All you need to do is set an AfterUpdate event for the field.

If Not IsNull(Me.CountryCode) Then
Me.CountryCode = "+" & Me.CountryCode
End If

Try that and see what happens.



--
Regards,

PJ
Please rate this post using the vote buttons if it was helpful.
 
M

MikeF

Thank you.
That works on AfterUpdate, but the field [and all records] are already there.
How do I update all existing records in Form.Dir ?

Regards,
- Mike
 
P

PJFry

Your best bet is to use an update query. In your Update To statement on the
CountryCode field use "+" & [CountryCode]. Make sure the [ ] are there or
you might update everyting to the text +CountryCode.
--
Regards,

PJ
Please rate this post using the vote buttons if it was helpful.



MikeF said:
Thank you.
That works on AfterUpdate, but the field [and all records] are already there.
How do I update all existing records in Form.Dir ?

Regards,
- Mike

Linq Adams via AccessMonster.com said:
It is a text field, per the original post.

This code will do the job. You have to be careful, when using the ampersand,
to leave a space between the components you're stringing together:

Private Sub CountryCode_AfterUpdate()
If Not IsNull(Me.CountryCode) Then
Me.CountryCode = "+" & Me.CountryCode
End If
End Sub
 
M

MikeF

Thank you.
But merely would like the form to add the + [only in the form].
The field is there, and just need to change CountryCode to whatever syntax
works for +CountryCode [ie +44 if it's England] in the form.

Regards,
- Mike

PJFry said:
Your best bet is to use an update query. In your Update To statement on the
CountryCode field use "+" & [CountryCode]. Make sure the [ ] are there or
you might update everyting to the text +CountryCode.
--
Regards,

PJ
Please rate this post using the vote buttons if it was helpful.



MikeF said:
Thank you.
That works on AfterUpdate, but the field [and all records] are already there.
How do I update all existing records in Form.Dir ?

Regards,
- Mike

Linq Adams via AccessMonster.com said:
It is a text field, per the original post.

This code will do the job. You have to be careful, when using the ampersand,
to leave a space between the components you're stringing together:

Private Sub CountryCode_AfterUpdate()
If Not IsNull(Me.CountryCode) Then
Me.CountryCode = "+" & Me.CountryCode
End If
End Sub
 
P

PJFry

Are you not wanting to store the + with the CountryCode? I ask because the
code we gave you will add and store the + sign. It sounds like you don't
want the + stored, you just want it visible on the form. Is that correct?
--
Regards,

PJ
Please rate this post using the vote buttons if it was helpful.



MikeF said:
Thank you.
But merely would like the form to add the + [only in the form].
The field is there, and just need to change CountryCode to whatever syntax
works for +CountryCode [ie +44 if it's England] in the form.

Regards,
- Mike

PJFry said:
Your best bet is to use an update query. In your Update To statement on the
CountryCode field use "+" & [CountryCode]. Make sure the [ ] are there or
you might update everyting to the text +CountryCode.
--
Regards,

PJ
Please rate this post using the vote buttons if it was helpful.



MikeF said:
Thank you.
That works on AfterUpdate, but the field [and all records] are already there.
How do I update all existing records in Form.Dir ?

Regards,
- Mike

:

It is a text field, per the original post.

This code will do the job. You have to be careful, when using the ampersand,
to leave a space between the components you're stringing together:

Private Sub CountryCode_AfterUpdate()
If Not IsNull(Me.CountryCode) Then
Me.CountryCode = "+" & Me.CountryCode
End If
End Sub
 
J

JimBurke via AccessMonster.com

I believe you said that the field will not be updated by the user. If that's
the case, then don't use a bound field. Leave the bound field on the form but
set it's visible property to False. Create an unbound textbox and set it's
ControlSource property to =IIf(IsNull(CountryCode),"","+" & CountryCode)).
This will display the field with a + in front of it if it has a value,
otherwise it will be blank. Make sure you put spaces before and after the "&".
 
J

JimBurke via AccessMonster.com

WHoops, I think I put an extra ')' on the end there.
I believe you said that the field will not be updated by the user. If that's
the case, then don't use a bound field. Leave the bound field on the form but
set it's visible property to False. Create an unbound textbox and set it's
ControlSource property to =IIf(IsNull(CountryCode),"","+" & CountryCode)).
This will display the field with a + in front of it if it has a value,
otherwise it will be blank. Make sure you put spaces before and after the "&".
Access 2007, have a text field called CountryCode.
[quoted text clipped - 6 lines]
Thanx,
-Mike
 
J

JimBurke via AccessMonster.com

WHoops, I think I put an extra ')' on the end there.
I believe you said that the field will not be updated by the user. If that's
the case, then don't use a bound field. Leave the bound field on the form but
set it's visible property to False. Create an unbound textbox and set it's
ControlSource property to =IIf(IsNull(CountryCode),"","+" & CountryCode)).
This will display the field with a + in front of it if it has a value,
otherwise it will be blank. Make sure you put spaces before and after the "&".
Access 2007, have a text field called CountryCode.
[quoted text clipped - 6 lines]
Thanx,
-Mike
 
M

MikeF

Thanx to all.

I made this happen by putting \+0000 in the InputMask property.

Appreciate everyone's input.
Regards,
- Mike
 
Top