Results 1 to 5 of 5
  1. #1
    Wil2003 is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Aug 2017
    Posts
    2

    Question First Non Zero of Value under a Field

    Hi I have started using Access for 2 weeks and appreciate if someone can offer helps on my problem below.

    Say, I have a table as below:

    1. All the records are in numerics
    2. The first three columns (Date, Time, Results) are given


    3. The fourth column (New) is the column that I want to create
    4. The fourth column should look at the value in "Results" and find the first non-zero value (ie, 1 or -1) and the fill the records below with this non-zero value found for a particular day.
    5. For a new date, repeat the process, ie, find the first non-zero value for that date, and fill the records with that value for the rest of that date.

    Thanks in advance for any help.

    Date Time Results New
    20101001 1000
    20101001 1100
    20101001 1200 1 1
    20101001 1300 1
    20101001 1400 -1 1
    20101001 1500 -1 1
    20101002 1000
    20101002 1100
    20101002 1200
    20101002 1300 -1 -1
    20101002 1400 1 -1
    20101002 1500 -1
    20101002 1600 1 -1

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You could use a recordset, opened on SQL that ordered by date and time. Within a loop of that recordset, use a variable to track when the date changes and another to test the results field. Use the .Edit method of the recordset to update records when appropriate.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Set ORDER BY property in table design to: [Date], [Time].

    Then try:

    SELECT Table1.Date, Table1.Time, Table1.Results, Query2.MinOfTime, IIf([Time]>=[MinOfTime],[FirstOfResults],Null) AS New
    FROM
    (SELECT Query1.Date, Min(Query1.Time) AS MinOfTime, First(Query1.Results) AS FirstOfResults
    FROM (SELECT Table1.Date, Table1.Time, Table1.Results FROM Table1 WHERE Not Table1.Results Is Null) AS Query1
    GROUP BY Query1.Date) AS Query2 INNER JOIN Table1 ON Query2.Date = Table1.Date;


    Date is a reserved word and should not use reserved words as names for anything.
    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.

  4. #4
    Wil2003 is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Aug 2017
    Posts
    2
    Thanks very much Paul and June7. I guess I have to first get myself familiar with SQL. Will get back after trying.
    Thanks again.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 6
    Last Post: 06-26-2015, 08:55 PM
  2. Replies: 17
    Last Post: 03-16-2014, 10:52 PM
  3. Replies: 3
    Last Post: 12-27-2013, 02:33 PM
  4. Replies: 1
    Last Post: 03-03-2012, 10:17 PM

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