Input Mask Default Value

I

Ivan Grozney

My users would like the area code to be defaulted but allow then to change
it. So I create the input mask and set the default value. However, if they
don't type in a phone number then the record gets stored with the area code
default. So I kluged a way to go through the database (very small) to look
for the area code only in the field and null it out. It seems to me there
must be a better way.

Here is what I have on my text box for the phone number

Input Mask: \(999") "000\-0000;0;_
Default Value: 281

On Enter Event Me![txtPhone].SelStart = 5

Is there a way to have an editable default within the input mask itself?

I tried "(281) "000\-0000;0;_ but it won't let me edit the 281.

tia

Vanya
 
B

Beetle

You may need to use code to do what you want. This is untested, so you may
need to play around with it to make it work, but here is an idea you
could try. In the After Update event of your control;

Private Sub txtPhone_AfterUpdate

Dim strAreaCode As String
strAreaCode = "281"

If Len(Me.txtPhone) = 7 Then 'user did not enter an area code
Me.txtPhone = strAreaCode & Me.txtPhone
ElseIf Len(Me.txtPhone) = 10 Then
'do nothing
Else 'user typed an invalid length
msgbox "Invalid phone number length"
Me.txtPhone.Undo
End If

In this case I would remove the input mask, and use a format property
of (@@@) @@@-@@@@, and tell your users not to type the
parentheses or the dash. The format will take care of that.

Like I said, it's untested but you might give it a try.

Good luck
 
B

Beetle

Actually, you might need to do it this way

Dim strPhoneNumber As String

If Len(Me.txtPhone) = 7 Then 'user did not enter an area code
strPhoneNumber = "'281" & Me.txtPhone & "'"
Me.txtPhone = strPhoneNumber
ElseIf Len(Me.txtPhone) = 10 Then
'do nothing
Else 'user typed an invalid length
msgbox "Invalid phone number length"
Me.txtPhone.Undo
End If

Sorry, I don't have "access" to Access right now, so I'm just winging it.
 
I

Ivan Grozney

Sean,

Thanks. I'll try it out.

Vanya

Beetle said:
Actually, you might need to do it this way

Dim strPhoneNumber As String

If Len(Me.txtPhone) = 7 Then 'user did not enter an area code
strPhoneNumber = "'281" & Me.txtPhone & "'"
Me.txtPhone = strPhoneNumber
ElseIf Len(Me.txtPhone) = 10 Then
'do nothing
Else 'user typed an invalid length
msgbox "Invalid phone number length"
Me.txtPhone.Undo
End If

Sorry, I don't have "access" to Access right now, so I'm just winging it.
--
_________

Sean Bailey


Ivan Grozney said:
My users would like the area code to be defaulted but allow then to change
it. So I create the input mask and set the default value. However, if they
don't type in a phone number then the record gets stored with the area code
default. So I kluged a way to go through the database (very small) to look
for the area code only in the field and null it out. It seems to me there
must be a better way.

Here is what I have on my text box for the phone number

Input Mask: \(999") "000\-0000;0;_
Default Value: 281

On Enter Event Me![txtPhone].SelStart = 5

Is there a way to have an editable default within the input mask itself?

I tried "(281) "000\-0000;0;_ but it won't let me edit the 281.

tia

Vanya
 

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

Similar Threads


Top