Results 1 to 8 of 8
  1. #1
    Geo21 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2014
    Posts
    20

    Finding calculated fields

    Hi.

    I have the following problem.

    I use before update event in a form to loop through all controls and find numerical values in order to round them to 2 decimal places. The problem is that I get error message for calculated fields (numbers created from expressions in other words). To solve this, I locked the subject fields and added .locked = False in the criteria. Though, since I want to do this in every form, it will be annoying to lock all the fields.



    Is there a method to check if the Field is a result of calculation, thus not editable?

    Thanks.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    By calculated fields, do you mean Calculated type field in table?

    Why not set the Format and DecimalPlaces properties to display only 2 decimals?

    Why is this necessary? Users should input data to only 2 decimal places and you want to correct?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Geo21 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2014
    Posts
    20

    Finding calculated fields

    By calculating field I mean a normal text box, containing a result from an expression such as addition. It is usually in a query.

    Users are supposed to input 2 decimal places, but there is also the error factor, as a result, the number will be shown as 2 decimals, but the value stored will be the actual input and I don't want that.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Can use code behind user input textbox to correct their input. In the textbox AfterUpdate event:

    Me.textboxname = Round(Me.textboxname,2)

    Be aware that Round() function in Access uses even/odd rule.

    Round(3.465,2) = 3.46
    Round(3.475,2) = 3.48

    If you want to save value of calculated textbox, that requires code to populate a field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Geo21 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2014
    Posts
    20

    Finding calculated fields

    June,

    Thanks for the answers.

    Though, I don't want the calculated fields to be updated. The question is, is there any kind of code so they be excluded?

    Such as

    If ctl {not a result of expression} then
    Round(ctl, 2)
    End if

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    You can use the Tag property of control. Put whatever text you want into the property - maybe "Calc". Then code can exclude those controls.

    If ctl.Tag <> "Calc" Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Geo21 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2014
    Posts
    20

    Finding calculated fields

    Thanks a lot.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Possible alternative is for code to check if there is = sign in the textbox ControlSource.

    If Not ctl.ControlSource LIKE "=*" Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Finding duplicates in two fields
    By skipnick in forum Access
    Replies: 6
    Last Post: 12-10-2013, 01:29 PM
  2. Replies: 12
    Last Post: 10-01-2013, 12:59 PM
  3. Replies: 4
    Last Post: 06-18-2013, 07:36 AM
  4. Replies: 1
    Last Post: 01-30-2013, 03:27 PM
  5. Calculated fields
    By Madmax in forum Forms
    Replies: 1
    Last Post: 06-17-2011, 08:36 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