Results 1 to 6 of 6
  1. #1
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168

    Change Images in Continuous Forms based on Data in Table

    First .. my brain is tired but here goes.



    I have a continuous form for sleep data .. I know I really need some sleep right about now.

    But I have the user rate the sleep (database for insomnia sufferers) .. and enter a rating from 1 to 5. That is stored in the table as an Integer .. ie 1 to 5.

    I want them to be able to see on the continuous form .. the value of the rating 'in stars'. I have included a sample pic below.
    So for a 1 rating .. they would see 1 star, 2 rating .. 2 stars.

    I just have it displaying 4 stars right now for demo purposes.

    Basically I need the Stars to match the displayed Rating .... just not sure how to do it on a continuous form.

    I am using an Image control (Linked to file). I am more interested in the easiest way to accomplish this. I am not that familiar with all the nuances of continuous forms.
    So there will be a total of 5 possible images that I need to link here.

    The images are like 2k so pretty tiny .. but it is not really an issue.


    I will work on it .. but it would be nice if someone could let me know the trick on this one. I assume that I just need to change the "Picture" attribute of the field as needed.

    Take care ..
    Kevin

    Click image for larger version. 

Name:	Sleep.jpg 
Views:	18 
Size:	64.5 KB 
ID:	24209

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Code:
     I assume that I just need to change the "Picture" attribute of the field as needed.
    If the rating image (stars) control is unbound, that won't work. On a continuous form, when you make a change to an unbound control (value or appearance), it changes the appearance of all the occurances of that control. Conditional formatting won't work either, because while it can change the appearance (colours, font, etc), it cannot change the content.

    I don't think you can do what you want to do without including the image data (as links to images) as part of your table.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    If you have a field in your table /record, could you not do something like

    iif( rating = 1 , "*"........iif(rating = 5, "*****"

  4. #4
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Thank you .. I really like the IIF solution .. simple. I will try that and see how far I get.

    Just a ? .. how could I attach the image into the table and just display that for each record ?? As they are very small and max 365 per year, the increase in size would not be an issue.

  5. #5
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Ok ... some progress. I have managed to attach the image files directly into a field and have it show on the Continuous form. That is the first part as displayed below.

    But I have no idea how to programmatically insert the image into the table as needed. I have never used attachments before so this is all new to me. I manually added them to the table.

    So for example .. if there is one star rating I need to insert Image file .. 1.png" ... or 2 start image file "2.png"

    I would appreciate some help on that one. But right now .. my form displays as I need it to once I can get the attachment into each record.

    Right now .. I am just testing but will start with real data soon as I can get that part working. I will be removing the actual rating field on the far right end once I get the stars going properly.

    Thanks for all your help .. ;-)

    Click image for larger version. 

Name:	Sleep1.jpg 
Views:	16 
Size:	82.0 KB 
ID:	24210
    Last edited by edmscan; 04-01-2016 at 10:09 PM.

  6. #6
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    It is done .. thankful for code snippets on the net for this one. It is pretty simple and there will ever be only 1 attachment per record so it works.

    If anyone has any suggestions for improvement let me know.

    Dim strSQL As String

    Dim db As DAO.Database
    Dim rsParent As DAO.Recordset2
    Dim rsChild As DAO.Recordset2

    Set db = CurrentDb

    strSQL = "SELECT TOP 1 tblSleep.SleepDate, tblSleep.SleepData FROM tblSleep ORDER BY tblSleep.SleepDate DESC;"

    Set rsParent = db.OpenRecordset(strSQL, dbOpenDynaset)

    With rsParent

    .MoveFirst

    rsParent.Edit

    Set rsChild = rsParent.Fields("SleepData").Value

    rsChild.AddNew
    rsChild.Fields("FileData").LoadFromFile ("C:\Desktop\Databases\Sleep\1.png")

    rsChild.Update
    rsParent.Update


    End With

    rsChild.Close
    rsParent.Close

    Set rsChild = Nothing
    Set rsParent = Nothing
    Set db = Nothing

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

Similar Threads

  1. Change color on textbox in a Continuous Forms
    By barby.pava in forum Forms
    Replies: 20
    Last Post: 03-30-2016, 08:01 AM
  2. Replies: 2
    Last Post: 04-22-2014, 02:48 PM
  3. Clone data in continuous forms
    By maddoctor in forum Forms
    Replies: 3
    Last Post: 11-19-2012, 11:57 AM
  4. Replies: 1
    Last Post: 10-22-2009, 03:32 AM
  5. Replies: 17
    Last Post: 08-26-2009, 11:27 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