Results 1 to 6 of 6
  1. #1
    lukeh81 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    3

    Help Query Conversion from Excel

    Hi,



    I am trying to create a query where:

    SWL_mBGL (= water level below ground level) is calculated using tbl_Water_Levels.SWL_mBTOC (water level below top of casing, which is entered manually) and tbl_TOC_Offset.TOC_mAGL (a table which shows the height above ground level of the top of casing). It must take into account the fact that the TOC_mAGL can change over time, eg. if it gets cut down from 1m to 0.5 m above ground level due to being hit by a car. So as far as a water level measurement is concerned, if a measurement is taken on a date between the Start_Date and End_Date of that TOC_mAGL row, will that value be used. Where there is no End_Date, it would be good to assume it is currently active.

    So, in the case of HoleA on 1/01/2001, the SWL_mBGL will be 9, but then on the 1/01/2010 it will be 8.


    The other issue I'm trying to solve is for the field 'Previous_SWL_mBTOC'. I simply want to be able to show the last SWL_mBTOC measurement for that particular Hole_ID according to date.

    So, for HoleB on 1/01/2020, this field will have 101 in it (not 100, 20 or 10), regardless of how the table is sorted and filters are activatedt (eg. whether Measured_Date is sorted from highest to lowest or lowest to highest, makes no difference)

    Click image for larger version. 

Name:	query_pic.png 
Views:	30 
Size:	22.0 KB 
ID:	51844

    This table should be a query, the actual table won't have the last 3 fields.



    I have attached a zip containing the Access File.
    tbl_Collars holds the Primary Key for Hole_ID.
    Calculating mRL is simply mRL: [tbl_Collar.Elevation-SWL_mBGL]

    Any help would be greatly appreciated

    Cheers,
    Luke
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Really helps if you post details of the issue?

    We are good, but not that good.

    FWIW I managed to find this much of the O/P's post


    Today, 05:23 AM
    lukeh81 started a thread Help Query Conversion from Excel in Queries
    Hi, I am trying to create a query where: SWL_mBGL (= water level below ground level) is calculated using tbl_Water_Levels.SWL_mBTOC (water...
    Today, 05:23 AM
    lukeh81 started a thread Help Query Conversion from Excel in Queries
    Hi, I am trying to create a query where: SWL_mBGL (= water level below ground level) is calculated using tbl_Water_Levels.SWL_mBTOC (water...
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Post 1 was re-moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi Luke

    I believe your table structures are wrong.

    I think you need a table listing details of specific Holes.

    Then you need a related table to enter details of the Water Levels for Each specific Hole.

  5. #5
    xps35's Avatar
    xps35 is online now Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    299
    Something like this?
    Code:
    SELECT tbl_Water_Levels.ID, 
           tbl_Water_Levels.Hole_D, 
           tbl_Water_Levels.Measured_Date, 
           tbl_Water_Levels.SWL_mBTOC, 
           SWL_mBTOC-TOC_mAGL AS SWL_mBGL, 
           DMax("SWL_mBTOC","tbl_Water_Levels","Hole_D = '" & [tbl_Water_Levels].[Hole_D] & "' AND Measured_Date<#" & [Measured_Date] & "#") AS Previous_SWL_mBTOC
    FROM tbl_Water_Levels INNER JOIN tbl_TOC_Offset ON tbl_Water_Levels.Hole_D = tbl_TOC_Offset.Hole_ID
    WHERE Measured_Date>=Start_Date And Measured_Date<=Nz(End_Date,Date());
    Groeten,

    Peter

  6. #6
    lukeh81 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    3
    Thanks for the responses and sorry for the late reply to them. I thought my post got deleted after I tried to edit it!

    Thanks Peter, that code you made did the trick. Much appreciated.

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

Similar Threads

  1. Replies: 14
    Last Post: 12-30-2023, 06:23 AM
  2. Excel VBA conversion to Access VBA
    By dbguy in forum Modules
    Replies: 3
    Last Post: 06-25-2020, 04:06 PM
  3. excel conversion/import/manipulation
    By Jen0dorf in forum Access
    Replies: 4
    Last Post: 03-22-2016, 01:41 PM
  4. Replies: 3
    Last Post: 09-14-2011, 05:27 PM
  5. Conversion from Excel to Access
    By TMG in forum Import/Export Data
    Replies: 1
    Last Post: 10-20-2009, 12:48 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