Solved Copying telephone numbes (1 Viewer)

Eljefegeneo

Still trying to learn
Local time
Today, 14:35
Joined
Jan 10, 2011
Messages
904
I have been trying to figure out a way to copy a telephone number that is usually in the format (800)-555-1212 into a form. The form is formatted for telephone numbers so the input mask is (???)-???-????. Right now when I copy the number to the telephone control it only pastes the area code. While the above is the usual format for a telephone number that I am copying, there are other formats like ???.???.???? and ???-???-????. Any suggestions on how I might do this? Thanks.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:35
Joined
Jul 9, 2003
Messages
16,245
Well I'd start off with Mintys code in this thread here:-


You can use it to specify which characters you want to strip from the string and just leave yourself with just numbers.

I suspect Mintys code would also remove any spaces, but if not, there are plenty of routines on Access World Forums (AWF) for removing spaces.

I used Minty's code to remove illegal characters from the names of Excel sheets I created from MS Access. I blogged about it here:-

 

Isaac

Lifelong Learner
Local time
Today, 14:35
Joined
Mar 14, 2017
Messages
8,738
I have been trying to figure out a way to copy a telephone number that is usually in the format (800)-555-1212 into a form. The form is formatted for telephone numbers so the input mask is (???)-???-????. Right now when I copy the number to the telephone control it only pastes the area code. While the above is the usual format for a telephone number that I am copying, there are other formats like ???.???.???? and ???-???-????. Any suggestions on how I might do this? Thanks.
Normally in Access (especially), and even (preferably) in Excel, we don't copy and paste. Anything. We write code to set a value equal to something.

I assume you have some code of some kind - you should post it or else we're just guessing
 

Eljefegeneo

Still trying to learn
Local time
Today, 14:35
Joined
Jan 10, 2011
Messages
904
No, I am getting a number from a web page and copying it, then pasting it to the forms telephone number field. I was hoping that there would be a simple anser for this, but perhaps I need to have an unbound field, to which I copy the formatted telephone number then when I do something like double click it, strips the unwanted characters and then I can copy and pasted it to the telephone field. If it is only numbers say 8005551212 it will copy perfectly.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:35
Joined
Jul 9, 2003
Messages
16,245
No, I am getting a number from a web page and copying it, then pasting it to the forms telephone number field. I was hoping that there would be a simple anser for this, but perhaps I need to have an unbound field, to which I copy the formatted telephone number then when I do something like double click it, strips the unwanted characters and then I can copy and pasted it to the telephone field. If it is only numbers say 8005551212 it will copy perfectly.

You are on the right track with that.

Your first step is to create a small sample database with a single table called "tblTel" to hold the telephone numbers.

Create a form based on "tblTel" which will have a field displayed in it where you can enter the telephone number into the telephone field in "tblTel"

Add an unbound text box.

Add a command button.

To test that a command button is working right, add the code to have the command button open a message box saying 'hello" .

Now change the command button code so that it takes text from the unbound textbox and shows it in the message box.

Change the command button code so that it takes the text of the unbound textbox and places it in the bound text box.

Look at the code I posted a link to earlier, the stripper function. Copy it and paste it into your form module next to the command button code.

Change the command button code yet again so that it Calls this function and also passes the unbound text box contents into the stripper function as a parameter and returns the result into the bound text box.

Everytime any of these steps fail, and it will, post here for help and I am sure someone will point you in the right direction.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:35
Joined
Jul 9, 2003
Messages
16,245
I've done a YouTube video demonstrating how to use the steps I have suggested above to answer this question...

How to Answer your own Question - Nifty Access​

 

Eljefegeneo

Still trying to learn
Local time
Today, 14:35
Joined
Jan 10, 2011
Messages
904
Update: Using the function found in a previous post, fStripIllegal, which I modified to include some additional characters, I went through my usual trial and error method of solving problems and came up with the following function. First I added an unbound control to the form and called it txtTel. Now when I paste the telephone number into this control it automatically adds the corrected formatted telephone number to my Telephone field which has an input mask. The function is in the OnChange() event of the unbound control txtTel.

Code:
Function UpdateTel()
If Me.Dirty Then
Me.Dirty = False
End If

Dim NewTel As String
  NewTel = txtTel
     fStripIllegal NewTel
         Me.txtTel = Trim(NewTel)
             txtTel = Replace(txtTel, " ", "")
                  Me.Telephone = Format(Me.txtTel, "(###) ###-####")
End Function
I had to add the Tim and Replace features to delete any spaces and then I had to reformat the string of numbers so that it pasted correctly.
Thanks to everyone who helped on this. Much appreciated.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:35
Joined
Sep 21, 2011
Messages
14,047
Isn't that then storing the format?, when I would have thought you just want the numbers and apply thr format when showing them?
 

Eljefegeneo

Still trying to learn
Local time
Today, 14:35
Joined
Jan 10, 2011
Messages
904
I don't know if I can answer that question. The Telephone field is a text field with the input mask of !\(999") "000\-0000;0;_
When pasting the text (number) into the telephone field it is only a continuous string. The control on the form shows it to be (XXX)-XXX-XXXX.

In any case, my question is solved to my satisfaction, which I have been told in many previous posts, if you like it and it works, you have solved your problem. May not be the best or easiest resolution, but it is solved. Thanks.

My money is on Tampa Bay. got my $1 in the other day.
 

Users who are viewing this thread

Top Bottom