displaying phone numbers (as an example)

C

Cheese_whiz

I want to know how to modify the display of data input by a user. I'm sure a
"classic" example would be to take a 7 digit number (phone number) and add a
hyphen to it when the phone number field loses focus.

I think I need code in the after update field, but I don't know how to tell
it how to display the numbers. I think the start would be something like
this:

Sub phoneField_after update
If Len(me.phoneField) = 7, then me.phoneField = something & "-" & something
End If
End Sub

Can someone fill in the somethings and just verify that's the right way to
go about it? I searched but I don't even know what you'd call this "process"
of modifying and then redisplaying user input.

Does it change things if I don't necessarily want the added elements (like
the hypen) actually stored in the table?

Thanks (again),
CW
 
L

LilMorePlease

Great news! No coding for this is necessary! Simply right click the text box
and go to InputMask.....
 
C

Cheese_whiz

I looked at the input mask option, but I get the impression it's not really
the best way to handle it.

For one, I want to be able to accept area codes, but I don't want them
required and I don't want people to have to tab past the area code to get to
the number. With input masks, I don't think that's possible.

Two, with input masks you pretty much need to specify the max numbers which
eliminates including any overseas phone numbers which, while unlikely needed
for this app, I just object to on principle *G*

Anyway, I may be forced into that option if I don't figure this out, but I'm
holding out for now.

Thanks a lot for the reply,
CW
 
F

fredg

I want to know how to modify the display of data input by a user. I'm sure a
"classic" example would be to take a 7 digit number (phone number) and add a
hyphen to it when the phone number field loses focus.

I think I need code in the after update field, but I don't know how to tell
it how to display the numbers. I think the start would be something like
this:

Sub phoneField_after update
If Len(me.phoneField) = 7, then me.phoneField = something & "-" & something
End If
End Sub

Can someone fill in the somethings and just verify that's the right way to
go about it? I searched but I don't even know what you'd call this "process"
of modifying and then redisplaying user input.

Does it change things if I don't necessarily want the added elements (like
the hypen) actually stored in the table?

Thanks (again),
CW

Sub phoneField_after update
If Len(me.phoneField) = 7 then
me.phoneField = Left([phoneField],3) & "-" & Right([PhoneField],4)
Elseif Len(Me![PhoneField]) = 10 Then
me.phoneField = Left([phoneField],3) & "-" &
Mid(Me![PhoneField],4,3) & "-" & Right([PhoneField],4)
End If
End Sub

You could also use:
If Len(Me![PhoneField]) = 7 Then
Me![PhoneField] = Format(Me![PhoneField],"@@@-@@@@")
ElseIf Len(Me![PhoneField]) = 10 then
Me![PhoneField] = Format(Me![PhoneField],"@@@-@@@-@@@@")
End if
 
C

Cheese_whiz

Thanks Fred! Works like a charm.

CW

fredg said:
I want to know how to modify the display of data input by a user. I'm sure a
"classic" example would be to take a 7 digit number (phone number) and add a
hyphen to it when the phone number field loses focus.

I think I need code in the after update field, but I don't know how to tell
it how to display the numbers. I think the start would be something like
this:

Sub phoneField_after update
If Len(me.phoneField) = 7, then me.phoneField = something & "-" & something
End If
End Sub

Can someone fill in the somethings and just verify that's the right way to
go about it? I searched but I don't even know what you'd call this "process"
of modifying and then redisplaying user input.

Does it change things if I don't necessarily want the added elements (like
the hypen) actually stored in the table?

Thanks (again),
CW

Sub phoneField_after update
If Len(me.phoneField) = 7 then
me.phoneField = Left([phoneField],3) & "-" & Right([PhoneField],4)
Elseif Len(Me![PhoneField]) = 10 Then
me.phoneField = Left([phoneField],3) & "-" &
Mid(Me![PhoneField],4,3) & "-" & Right([PhoneField],4)
End If
End Sub

You could also use:
If Len(Me![PhoneField]) = 7 Then
Me![PhoneField] = Format(Me![PhoneField],"@@@-@@@@")
ElseIf Len(Me![PhoneField]) = 10 then
Me![PhoneField] = Format(Me![PhoneField],"@@@-@@@-@@@@")
End if
 
Top