Results 1 to 5 of 5
  1. #1
    RossPart is offline Novice
    Windows 11 Office 365
    Join Date
    Jan 2024
    Posts
    2

    After Update help with SQL Statement

    Hi,
    Using MS Access 365.
    Have a small library database. Table 'Titles' includes fields, TitleId and Status. Status is either "On Shelf" or "On Loan"

    Have a 'Borrower' Form with details of borrower.
    Have 'Borrowings' sub form which shows Borrowing History for Borrower by TitleID This form includes fields 'Date Borrowed' and 'Date Returned'

    So far all works well.

    So! I want to be able to switch the 'Status' field on the Titles Record, according to whether there is a value in the 'Date Borrowed' but not in the 'Date Returned' field, [On Loan] or, if a Book is returned, [On Shelf].

    Borrowings.pdf

    My thanks in advance.

  2. #2
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    436
    you can remove the Status field from table Titles but instead use Query to determine if it is On Loan or On Shelf.
    create a Query (qryTitleStatus):

    Code:
    SELECT 
             Titles.TitleID, 
             Titles.Title, 
             DCount("1","BorrowHistory","TitleID = " & [TitleID] & " And [Date Returned] Is Null") AS Out, 
             IIf([Out]=0,"On Shelf","On Loan") AS Status 
    FROM Titles;

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Quote Originally Posted by jojowhite View Post
    you can remove the Status field from table Titles but instead use Query to determine if it is On Loan or On Shelf.
    create a Query (qryTitleStatus):

    Code:
    SELECT 
             Titles.TitleID, 
             Titles.Title, 
             DCount("1","BorrowHistory","TitleID = " & [TitleID] & " And [Date Returned] Is Null") AS Out, 
             IIf([Out]=0,"On Shelf","On Loan") AS Status 
    FROM Titles;
    O/P might have more than one copy of various titles?

    I would have thought there would be a junction table for borrower and title and that table would have the DateBorrowed and DateReturned fields?
    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

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Might want to look at MS Lending Library template.
    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.

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Office 365
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    LendingLibraryMod-davegri-v03.zip

    Here's the Microsoft Lending Library app with many ills cleaned up.
    Removed spaces and special char from table names.
    Removed lookups in tables (except small value lists)
    Removed click events in reports
    Renamed table keys (_PK, _FK)
    Converted most macros to VBA
    Removed the screwy filtering methodology
    Removed deprecated methodology
    Removed attachments
    Removed some unneeded reports
    Changed from tabbed docs to overlapping
    Adjusted colors in all forms


    Some undesirable elements remain such as split forms that cannot be resized in any reasonable manner.

    Edit: Replaced v02 DB. Uploaded v03
    Replaced split forms with continuous forms - added Edit button to each row
    Cleaned up code to conform with changing table IDs from ID to _PK and _FK
    Last edited by davegri; 08-31-2025 at 03:26 PM.

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

Similar Threads

  1. Replies: 1
    Last Post: 10-29-2014, 10:19 AM
  2. Help on SQL Statement for Update Query
    By KCC47 in forum Queries
    Replies: 4
    Last Post: 12-31-2013, 07:02 AM
  3. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  4. SQL Update statement help
    By kalltim in forum Access
    Replies: 6
    Last Post: 01-18-2012, 07:30 AM
  5. Replies: 7
    Last Post: 08-17-2011, 01:49 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