Hi, Mike.
I'm confused. An Input Mask is normally used to assist the user in
formatting the input as he types, and to ensure that he completes the field.
It has no value that I can see once the data is already inputted.
Moreover, an Input Mask applies to the control--you cannot have a different
one for each record. That is why I suggested the Dialog form method, which
is also used when you're filtering one combo box by a previous one on a
continuous form. Since the masks I suggested were saving the formatting
characters to the unbound control on the dialog form, these characters were
saved to your main form control intact.
But, if you're not looking to assist the user during data entry and merely
wish to format the entry for subsequent display when editing and viewing the
record, my only other suggestion would be to create a custom function, such
that you convert the number-only input to the formatted input. Seems like
this would need to be "hard-wired", and would require error-checking to make
sure the number of digits entered matched the number required for that mask.
Something like, in the BeforeUpdate event of the Buyer-Office control:
Dim strPh as String ' Working string as entered into BuyerOffice
Dim blnInvalid As Boolean ' Set to true if # of characters is incorrect
strPh = Me![BuyerOffice]
blnInvalid = False
Select Case Me![CountryName]
Case 1 ' The code for a country with input mask (999) 000-0000
If len(strPh) <> 10 Then
blnInvalid = True
Else
Me![BuyerOffice] = "(" & left(strPh,3) & ")" & Mid (strPh,4,3) & "-" &
Right(strPh,4)
End If
' Other cases
End Select
If blnInvalid = True Then
Cancel = True
MsgBox "Wrong number of digits for this country. Please reenter."
End If
But, although the former solution requires three different procedures, it is
quite clean, and feels totally intuitive. Your choice.
Hope that helps.
Sprinks
MikeZz said:
Thanks for the help, maybe there is a simpler way....
I don't deal with TO many countries, so I don't think the Multiple formats
per country would be that big of an issue if I just have a multiple Country
Names for the same country...
ie CountryNames = Austria-Viena; Austria-Eisenerz; etc...
So, if I use that idea, could I add the following to the
BuyerOffice_AfterUpdate (which is the field for their office phone number):
Look up which country is already selected in the country code and then apply
the mask to the phone number I just entered in BuyerOffice
Private Sub cboBuyerOffice_AfterUpdate()
On Error Resume Next
Dim strInputMask As String
strInputMask = Me!cboCountryCode.Column(2)
Me!BuyerOffice = Format(Me!BuyerOffice, strInputMask)
End Sub
Thanks,
MikeZz
:
Hi, Mike.
In light of the complexities Andy brings up, it might still be worth it.
You'd have to filter a second combo box, however, by the choice of Country,
to narrow it to the types of codes therein. This would necessitate detail
table of Country, and the input masks would be stored there.
Sprinks
:
I have a contact list with phone number fields. The contacts could be from a
number of countries each with a different phone number mask.
The contact table has a "Country" field which is a lookup from a Country
Table.
I was thinking about adding a Phone Number mask field to the Country Table
and somehow use that to format the phone numbers.
So, is it possible on my contact form, that after I select the country for
the contact, the form knows to lookup the mask from the country table and it
apply it?
This is a continous form with all the fields in the "detail" section.
The other question is does this apply a potentially different mask to all
visible phone numbers? ie 1st row shows US mask, 2nd row shows Germany
mask...etc...
Thanks,