Add a + to Country Code field

  • Thread starter Thread starter MikeF
  • Start date Start date
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
 
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.
 
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
 
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.
 
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
 
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
 
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
 
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
 
Thanx to all.

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

Appreciate everyone's input.
Regards,
- Mike
 
Back
Top