Results 1 to 4 of 4
  1. #1
    shod90 is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Jan 2016
    Posts
    134

    Loop through Details section in access report

    Dear Gents,


    Is there a way to loop through access report details section ? .. I need to do the following:
    1- Loop through Details section for all items.
    2- Check if the sell price is smaller than buy price then change the forecolor to red for this record only.
    3- Continue looping and check if the sell price is larger than sell price then make the forecolor to black again.

    something like.

    ------------------------------------------------------
    |Order No | Date | Buy price | Sell Price|
    ------------------------------------------------------
    |1 | 7/4/2017| 20 | 18 |
    -------------------------------------------------------
    |2 | 7/4/2017| 20 | 22 |
    -------------------------------------------------------
    |3 | 7/4/2017| 20 | 18 |
    -------------------------------------------------------
    |4 | 7/4/2017| 20 | 18 |
    -------------------------------------------------------

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    In the detail ON PRINT event,
    Code:
    if txtSell < txtBuy then
       TxtNum.forecolor = vbRed
    else
      TxtNum.forecolor = vbBlack
    endif

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,426
    you will need to use conditional formatting rather than looping through the detail controls

    it would be something like

    expression is....[Sell Price]<[Buy Price]

    then set the forecolor to red

  4. #4
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by shod90 View Post
    Dear Gents,
    Is there a way to loop through access report details section ?
    Access report ready have a built in method to handle this.

    There are events that fire as the report process the records. Yiou can add VBA code to eh events to do what yu need.


    Quote Originally Posted by shod90 View Post
    .. I need to do the following:
    1- Loop through Details section for all items.
    2- Check if the sell price is smaller than buy price then change the forecolor to red for this record only.
    3- Continue looping and check if the sell price is larger than sell price then make the forecolor to black again.
    Thre are two ways to handle what you need:

    1) Use Conditional formatiung. See previous reply Ajax

    2) use VBA code in an event. In yur case the try the On Format or On Print events. See previous reply by ranman256


    I prefer to use Conditinal formtating when possible. Note: Conditional formatting works great on forms too

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

Similar Threads

  1. Replies: 6
    Last Post: 03-26-2013, 12:17 PM
  2. Replies: 3
    Last Post: 05-02-2012, 10:13 AM
  3. Page Break at end of Details section
    By noweyout in forum Reports
    Replies: 3
    Last Post: 04-21-2011, 12:02 PM
  4. Replies: 0
    Last Post: 11-23-2009, 09:19 PM
  5. Replies: 26
    Last Post: 11-06-2009, 10:16 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