none
format report telephone field RRS feed

  • Question

  •  

    I have searched this forum and the web and am not finding the answer.

    I have a local report using the Microsoft Report Viewer add in for VS 2005 Express.  I am trying to format a text field in a report that is a telephone number. 

    Instead of 8008898890 I want (800) 889-8890

     Any suggestions?  I have tried all of the format options such as {0Sad###) ###-####}

    None of them are working.

    Thursday, October 4, 2007 9:32 PM

Answers

  •  

    The format (###) ### - #### will work for you (no quotes around it in the Format property, and no braces) *if* the value that you're looking at is a number.

     

    IOW let's say that the contents of the cell is a literal 8008898890.  It won't work, because that will be a string.  if you put in the expression =8008898890 it will work.

     

    You can also do this with the Format function in your Value expression if you like, rather than using the Format property. 

     

    Code Block


    =Format(Fields!TestNumber.Value,
    "(###) ### - ####")

     

     

    Here, again, the format will work if the value is numeric. For example:

     

    Code Block


    =Format(8001234567,"(###) ### - ####")     <-- will work

    =Format("8001234567","(###) ### - ####")   <-- will not work

     

    =Format(Fields!TestNumber.Value,"(###) ### - ####")   <-- will work

    =Format(Fields!TestStringContainsANumber.Value,
                                   
    "(###) ### - ####")   <-- will not work

     

     

    ... so if your data value is not really a number, and if you want to do it this way, you need to through a CDbl() conversion around your data value. 

     

    This should work for you either inside the =Format() function, in the Value property, or standalone in the Value property in the expression if you want to put the Format template string in the Format property instead.

     

    Code Block

    =CDbl(Fields!TestStringContainsANumber.Value)      <-- will work with
                                                           Format property of 
                                                          
    "(###) ### - ####"

    =Format(CDbl("8001234567"),
                
    "(###) ### - ####")                   <-- will also work

    =Format(CDbl(Fields!TestStringContainsANumber.Value),
                
    "(###) ### - ####")                   <-- will also work

     

     

     

     

    HTH,

     

    >L<

    Sunday, October 7, 2007 4:05 PM

All replies

  •  

    The format (###) ### - #### will work for you (no quotes around it in the Format property, and no braces) *if* the value that you're looking at is a number.

     

    IOW let's say that the contents of the cell is a literal 8008898890.  It won't work, because that will be a string.  if you put in the expression =8008898890 it will work.

     

    You can also do this with the Format function in your Value expression if you like, rather than using the Format property. 

     

    Code Block


    =Format(Fields!TestNumber.Value,
    "(###) ### - ####")

     

     

    Here, again, the format will work if the value is numeric. For example:

     

    Code Block


    =Format(8001234567,"(###) ### - ####")     <-- will work

    =Format("8001234567","(###) ### - ####")   <-- will not work

     

    =Format(Fields!TestNumber.Value,"(###) ### - ####")   <-- will work

    =Format(Fields!TestStringContainsANumber.Value,
                                   
    "(###) ### - ####")   <-- will not work

     

     

    ... so if your data value is not really a number, and if you want to do it this way, you need to through a CDbl() conversion around your data value. 

     

    This should work for you either inside the =Format() function, in the Value property, or standalone in the Value property in the expression if you want to put the Format template string in the Format property instead.

     

    Code Block

    =CDbl(Fields!TestStringContainsANumber.Value)      <-- will work with
                                                           Format property of 
                                                          
    "(###) ### - ####"

    =Format(CDbl("8001234567"),
                
    "(###) ### - ####")                   <-- will also work

    =Format(CDbl(Fields!TestStringContainsANumber.Value),
                
    "(###) ### - ####")                   <-- will also work

     

     

     

     

    HTH,

     

    >L<

    Sunday, October 7, 2007 4:05 PM
  •  

    Lisa,

     

    Thank-you so very much for this information.   The CDbl method worked just like I needed it to!

     

    Joe

    Monday, October 8, 2007 1:56 AM