Results 1 to 5 of 5
  1. #1
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82

    trying to use conditional formatting to indicate where field content is unique

    I have a subform that displays a list of song titles linked to a particular album id. Some songs exist on more than one album, and I wanted to create a conditional format that would color any song that exists on multiple albums. I made a few attempts but so far nothing works. One thing that doesn't work, for example, is:

    Code:
    ("SELECT Count(LPContents.song_id) FROM LPContents where LPContents.song_id = " & [SongID])>1
    I don't know if this is close but I just have syntactical issues or whether this is completely improper and useless. It was just my best guess as something that seemed like it might work.

    Info on underlying structure: The song titles and song ids are in Songs, the list of albums is in LPs, and LPContents has a key to match each id in Songs to the id of a particular album in LPs. So I can create a list of titles with the query:



    Code:
    SELECT Songs.Title, Songs.SongID, LPContents.LP_id
    FROM LPContents INNER JOIN Songs ON LPContents.song_id = Songs.SongID
    WHERE ((([LPs].[LPID])=[LPContents].[LP_id]))
    ORDER BY LPContents.Side, LPContents.Track, Songs.SongID;

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    your query should show the count of the song in other albums
    select song, count (Song) as CountOfSong from table

    then the condit.formating will change color for count = 1

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    was the error something about not being able to have an aggregate function in a WHERE clause? If the first suggestion doesn't work for you, you might try using the HAVING keyword in your sql:

    ("SELECT Count([song_id]) AS CntLPC FROM LPContents WHERE [song_id] = " & [SongID] & " HAVING Count(song_id) >1")

    Assumes the ID is a number.

    You can also assign the name of a UDF (user defined function - not a sub) to conditional formatting expression.
    Last edited by Micron; 12-07-2018 at 06:23 PM. Reason: forgot to concatenate
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82
    I didn't quite get what I needed (or just didn't understand) from the replies, but while fooling around I found an alternative that works:
    Code:
    DCount("[LPContents.song_id]","LPContents","LPContents.song_id = " & [SongID])>1
    For some reason when I save this I get an error message, but it still works so far.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Error maybe because of the [ ] on the field name, should be [LPContents].[song_id] or just [song_id] or even song_id because there are no spaces nor special characters.

    Can simplify:

    DCount("*", "LPContents", "song_id = " & [SongID])>1
    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.

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

Similar Threads

  1. Replies: 5
    Last Post: 05-22-2017, 01:34 PM
  2. Replies: 1
    Last Post: 01-05-2017, 05:14 PM
  3. Conditional formatting for a empty field
    By Bradex in forum Forms
    Replies: 4
    Last Post: 03-18-2016, 09:11 PM
  4. Conditional Formatting on datetime field
    By Delta729 in forum Access
    Replies: 3
    Last Post: 05-06-2015, 03:37 PM
  5. Conditional Formatting based on another field - Part II
    By Harley Guy in forum Programming
    Replies: 8
    Last Post: 10-17-2013, 12:46 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