Results 1 to 13 of 13

Thread: data type

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    data type

    how do make a textbox numerical values only or make them a telephone number format. help would be very much appreciated.

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: data type

    The following code will only allow numeric values in TextBox1. It will allow a leading minus sign and will also allow a single decimal point.
    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    2. With Me.TextBox1
    3.     Select Case KeyAscii
    4.         Case ASC("0") To ASC("9")
    5.         Case ASC("-")
    6.             If InStr(1, .Text, "-") > 0 Or .SelStart > 0 Then
    7.                 KeyAscii = 0
    8.             End If
    9.         Case ASC(".")
    10.             If InStr(1, .Text, ".") > 0 Then
    11.                 KeyAscii = 0
    12.             End If
    13.         Case Else
    14.             KeyAscii = 0
    15.     End Select
    16. End With
    17. End Sub

    When you say telephone format, what do you mean? (it can vary by country)
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    Re: data type

    cheers for the info. i forgot to mention that i am using vba so can i use that code in vba. the telephone number is just the format in an access database.

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: data type

    This is vba code, so you will be OK there, you will just need to change the procedure name, replacing TextBox1 with the name of your textbox.

    Access telephone formats can vary depending on the regional setting, I think. Can you give me an example of the format you need? e.g. (xxx) xxx-xxxx
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    Re: data type

    (99999) 099099, that sorta range.

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: data type

    For phone format, in the InputMask property of the textbox, under the Data tab,
    enter:
    Code:
    !\(999") "000\-0000;;_
    or select/modify as needed from the dropdown tab. 9's mean area code is optional, 0's are required numbers. This will force entry in that format, it's not the format of the field in the table; you'd have to set that in the table itself.
    Tengo mas preguntas que contestas

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    Re: data type

    there aint a data tab. so i still aint got a clue on the telephone number part. as i said i am using vba within excel.

  8. #8
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: data type

    (99999) 099099
    So let me ask a few more Q's on this format.
    Do you want the braces () to be added automatically or do you want the user to entrer them?
    Will the area-code always be 5 digits?
    Will the phone number always be 6 digits?

    as i said i am using vba within excel.
    BTW, you never mentioned that you were using Excel
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    Re: data type

    oh soz dude. i am using vba in excel. yes i want them format. with brackets and 5 digits for area and 6 for phone number. but if brackets is a problem it dont matter to much.

  10. #10
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: data type

    Do you want the braces () to be added automatically or do you want the user to entrer them?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  11. #11
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: data type

    This should do it.
    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    2.     With TextBox1
    3.         Select Case KeyAscii
    4.             'Only allow numeric values
    5.             Case Asc("0") To Asc("9")
    6.                
    7.                 'If its the first character
    8.                 'Add the opening brace
    9.                 If .SelStart = 1 Then
    10.                     .Value = "(" & .Value
    11.                 End If
    12.                
    13.                 'If it is the sixth character
    14.                 '(five digits plus the opening brace)
    15.                 'Add the closing brace
    16.                 If .SelStart = 6 Then
    17.                     .Value = .Value & ") "
    18.                 End If
    19.                
    20.                 'Only allow 14 characters max
    21.                     '2 braces
    22.                     '5 area code
    23.                     '1 space
    24.                     '6 number
    25.                 If .SelStart > 14 Then
    26.                     KeyAscii = 0
    27.                 End If
    28.                
    29.             Case Else
    30.                 KeyAscii = 0
    31.         End Select
    32.     End With
    33. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    Re: data type

    automatically.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    Re: data type

    thank u very much mate. i will try it later. cheers for the help people.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width