Results 1 to 5 of 5
  1. #1
    RPB is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2019
    Posts
    3

    Formatting data size Single to a percentage

    When I use an expression to calculate a percentage the target field is Dim X as Single. It works but the result is 9.982935E-02. I have tried the Format(x, "Percent") and it gets an error 13 "Type Mismatch". I've tried virtually every combination of data types and I've run out of bullets. Any help would be appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    in the query that does the calc, set the field format to %.

    if you do this in code, you may be getting a string. Can you not just use a query?

  3. #3
    RPB is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2019
    Posts
    3
    Here's the vba code that invokes an error:

    Dim v_Temp_Prcnt as (I've tried single, double, integer and string)

    v_Cancer_Type_Prcnt = cnt_Type / 1172
    v_Temp_Prcnt = FormatPercent(v_Cancer_Type_Prcnt, 2) (this is the line that invokes the error)

    I have used a query to do the same thing and it works. I'm attempting to automate the process that gathers lots of data and it was easier to write some vba than it was to create umpteen queries that would have to be changed every time the data is refreshed. I have read some posts that percentages in VBA are difficult and I can't seem to find the right combination of data types that will create the desired results.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    =Format(field,"percent")
    =Format(field,"0.00%")

    but you assign it to a textbox or a variable that can hold it.
    assigning a percent to a single does not produce a pct.
    Format is just a way to view the #.

  5. #5
    RPB is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2019
    Posts
    3
    Problem solved! I created a text box control on a form (as you suggested) in the UI, moved the re-formatted value there and it works. Thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. font size in conditional formatting
    By ameedoo3000 in forum Access
    Replies: 4
    Last Post: 03-02-2019, 04:40 PM
  2. Percentage of Count (text) data in Access Query?
    By Antoine_Tokyo in forum Access
    Replies: 1
    Last Post: 11-28-2017, 08:51 PM
  3. Replies: 2
    Last Post: 10-30-2017, 01:42 PM
  4. Replies: 4
    Last Post: 09-25-2015, 07:28 AM
  5. Change Percentage Data Type
    By jo8701 in forum Access
    Replies: 1
    Last Post: 02-08-2012, 07:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums