Results 1 to 6 of 6
  1. #1
    xcheshirecat is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Posts
    10

    Event trigger at loading each record

    Hi,
    I need to execute some code to calculate what the numeric value is in fraction. I don't want to stock it in the database.
    When I use the "current" event, it changes the values in the unbound fields for each record. When I click the next one, it changes all of them for the calculation of the new record

    So, I need to know how to change unbound fields values only for each record. And I need to do it at loading

    Thanks

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Instead of the OnCurrent event you need to use the Control Source of the Unbound Textbox. In the Control Source you'd use something along this line:

    = [FieldA] + [FieldB]

    using your own calculating expression. Then each Unbound Textbox would hold the calculation appropriate for the given Record.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What code do you have to execute? Can you show us the code?

  4. #4
    xcheshirecat is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Posts
    10
    Quote Originally Posted by Missinglinq View Post
    Instead of the OnCurrent event you need to use the Control Source of the Unbound Textbox. In the Control Source you'd use something along this line:

    = [FieldA] + [FieldB]

    using your own calculating expression. Then each Unbound Textbox would hold the calculation appropriate for the given Record.

    Linq ;0)>
    thanks for the answer, but the calculation is REALLY more complicated than that.

    What I want to store is the numeric value, but I need to show is the fraction. One box for the whole number, one box for the numerator, and one box for the denominator


    That is calculated by this function (custom data type)
    Code:
    Function GetFraction(ByVal Num As Double) As NombreEnFraction
       If Num = 0# Then
       GetFraction.entier = 0
       GetFraction.numerateur = 0
       GetFraction.denominateur = 0
        Else
            Dim WholeNumber As Integer
            Dim DecimalNumber As Double
            Dim Numerator As Double
            Dim Denomenator As Double
            Dim a, b, t As Double
    
    
            WholeNumber = Fix(Num)
            DecimalNumber = Num - Fix(Num)
            Numerator = DecimalNumber * 10 ^ (Len(CStr(DecimalNumber)) - 2)
            Denomenator = 10 ^ (Len(CStr(DecimalNumber)) - 2)
            If Numerator = 0 Then
            GetFraction.entier = WholeNumber
            GetFraction.numerateur = 0
            GetFraction.denominateur = 0
            Else
                a = Numerator
                b = Denomenator
                t = 0
    
    
                While b <> 0
                    t = b
                    b = a Mod b
                    a = t
                Wend
                'If WholeNumber = 0 Then
                '    GetFraction = CStr(Numerator / a) & "/" & CStr(Denomenator / a)
                'Else
                '    GetFraction = CStr(WholeNumber) & " " & CStr(Numerator / a) & "/" & CStr(Denomenator / a)
                'End If
                GetFraction.entier = WholeNumber
                GetFraction.numerateur = Numerator / a
                GetFraction.denominateur = Denomenator / a
               
            End If
        End If
    
    
    End Function

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by xcheshirecat View Post

    ...but the calculation is REALLY more complicated than that...
    That was a simple example to show the method you needed to use! If it depends on a Function, that's fine, too! In the Control Source Property you start with the Equal Sign, as shown, then follow with the Custom Function, just remembering to refer to the Fields that are passed to the Function by enclosing them in Square Brackets

    [FieldName]

    rather then the usual way of referencing, in VBA, of

    Me.FieldName

    So you end up with (once again, this merely an example to show the method to use; you'll have to make adjustments for your situation) something like this:

    =CustomFunctionName([Field1], [Field2])
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    xcheshirecat is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Posts
    10
    It worked for the report part, but for the form, I need to put the data, but I need the user to modify it, which will change the invisible numeric value. If I use the function method, it doesn't allow edition

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

Similar Threads

  1. how to trigger a button event at same form
    By newaccess in forum Forms
    Replies: 10
    Last Post: 03-01-2013, 10:02 AM
  2. Trigger event with button click
    By AMAS in forum Forms
    Replies: 8
    Last Post: 06-07-2012, 09:42 AM
  3. event to trigger after new record
    By richlyn in forum Access
    Replies: 1
    Last Post: 03-02-2012, 10:26 AM
  4. Replies: 2
    Last Post: 07-24-2011, 08:50 PM
  5. Trigger subform event
    By tuna in forum Forms
    Replies: 0
    Last Post: 05-09-2010, 06:29 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