Results 1 to 6 of 6
  1. #1
    omnifold is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    4

    Subtraction of a number till it reaches zero

    What I need is a way to subtract .016 from a single number in a field and show the results in a report. I would like it to minus the .016 from a number till it reaches 0. I want to show it the report all the numbers.




    Field contains the value of 7(there is only one row of data in the field)

    I want a report to show

    7
    6.984
    6.968
    6.952

    and so on.

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Location
    India
    Posts
    931

    Subtraction of a number till it reaches zero

    I have a very simple example here I have a table with two fields ID(Autonumber) MyNumber Number Field.

    Now I have prepared a simple report using my Table and I have placed an unbound list box to show my the results of my subtractions. The code is as below


    Code:
    Private Sub Report_Load()
    Dim intMyNumber As Double
    Dim strMyString As String
    
    intMyNumber = Me.myNumber
    Do While intMyNumber > 0
        intMyNumber = intMyNumber - 0.016
    
    'I have added this part to show only positive results.
        If intMyNumber < 0 Then
            Exit Do
        Else
        
            If Len(strMyString) > 0 Then
                strMyString = strMyString & ";" & Format(intMyNumber, "0.000")
            Else
                strMyString = Format(intMyNumber, "0.000")
            End If
            
        End If
    Loop
    
    Me.List2.RowSource = strMyString
    End Sub

    The code is attached to the onLoad Event. Refer to Screen Shot Attached.
    Attached Thumbnails Attached Thumbnails ScreenShot.png  

  3. #3
    omnifold is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    4
    Thanks but I would like to to this there it would not require a list box. This way if the list is long it will print out correctly

  4. #4
    maximus's Avatar
    maximus is offline Expert
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Quote Originally Posted by omnifold View Post
    Thanks but I would like to to this there it would not require a list box. This way if the list is long it will print out correctly

    This can be done using a text box too. Lets have a test Box name txt1. Then the changes in the code will be as follows:

    Code:
    Private Sub Report_Load()
    Dim intMyNumber As Double
    Dim strMyString As String
    
    intMyNumber = Me.myNumber
    Do While intMyNumber > 0
        intMyNumber = intMyNumber - 0.016
    
    'I have added this part to show only positive results.
        If intMyNumber < 0 Then
            Exit Do
        Else
        
            If Len(strMyString) > 0 Then
                strMyString = strMyString & vbcrlf & Format(intMyNumber, "0.000")
            Else
                strMyString = Format(intMyNumber, "0.000")
            End If
            
        End If
    Loop
    
    Me.txt1= strMyString
    End Sub
    Make sure Can Grow Property of the text Box is set to Yes

  5. #5
    omnifold is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    4
    I did that I the text doesn't grow. The box is set to yes.

  6. #6
    omnifold is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    4
    Sorry it does in print view only. Thank you for your help

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

Similar Threads

  1. Subtraction of Two Fields
    By shafi_sunshine in forum Queries
    Replies: 5
    Last Post: 12-09-2012, 07:01 AM
  2. Replies: 4
    Last Post: 03-11-2012, 08:51 AM
  3. subtraction between records
    By JJCHCK in forum Programming
    Replies: 5
    Last Post: 10-11-2011, 12:57 AM
  4. Sum() everything till date
    By Medivh in forum Queries
    Replies: 3
    Last Post: 07-20-2010, 08:55 AM
  5. hide text box till you un-tick check box
    By islandboy in forum Access
    Replies: 14
    Last Post: 09-06-2009, 10:08 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