Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2005

Tip: Looking for answers? Try searching our database.

Working with percentages in queries

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Felipe - 04 Nov 2005 17:44 GMT
I’m working with calculated fields that have percentages, but the data entry
is like 43.5% my problem is that in order to multiply and get related
percentage of a number I have to divide by 100. Access read the number as 435
and if I set up to divided by 1000 I still have the risk of having I wrong
answer in the case of the percentage been smaller. For example: 9.5% is 95 to
access  and 43,5 is 435
Allen Browne - 04 Nov 2005 18:02 GMT
Paste the function below into a standard module.

Open your form in design view, right-click the text box where you want the
value to be interpreted as a percent, and choose Properties. On the Event
tab of the properties box, enter:
   =MakePercent([Text1])
replacing "Text1" with the actual name of your text box.

The code examines the text in the field. If the user typed a percent sign,
it leaves the value alone, because Access will interpret that correctly. If
not, it will divide by 100.

Public Function MakePercent(txt As TextBox)
On Error GoTo Err_Handler
   'Purpose:   Divide the value by 100 if no percent sign found.
   'Usage:     Set the After Update property of a text box named Text23 to:
   '               =MakePercent([Text23])

   If Not IsNull(txt) Then
       If InStr(txt.Text, "%") = 0 Then
           txt = txt / 100
       End If
   End If

Exit_Handler:
   Exit Function

Err_Handler:
   If Err.Number <> 2185 Then  'No Text property unless control has focus.
       MsgBox "Error " & Err.Number & " - " & Err.Description
   End If
   Resume Exit_Handler
End Function

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> I'm working with calculated fields that have percentages, but the data
> entry
[quoted text clipped - 5 lines]
> to
> access  and 43,5 is 435
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.