How to Set different images based on cell value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TravelingCat
    New Member
    • Feb 2010
    • 82

    #1

    How to Set different images based on cell value

    Hello,
    I have a continuous form, and i'm trying to set an image for each line in a cell named "assignType " based on its type. If type = 1 -> set ImageText, if type = 2 -> set ImageDecision. I tried to do this with Select Case, but the problem is it only remembers the last Case he was in. To make it more clear:
    Code:
    Dim rs As DAO.Recordset
    Set rs = Me.RecordsetClone
    Do While Not rs.EOF
    Select Case rs("assignType")
        Case 1:
        ImageText.Visible = True
        Case 2:
        ImageDecision.Visible = True
        End Select
    rs.MoveNext
    Loop
    So if the last record on a form is assign with type 2, then all the lines will have ImageDecision. Does anyone know how i can fix this?
    Thanks in advance
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Hmmm, Access has a "problem" with unbound controls in a Continuous form. The only solution I found was to add the field to the table and make sure it's filled to display it correctly.

    Nic;o)

    Comment

    • TravelingCat
      New Member
      • Feb 2010
      • 82

      #3
      Thanks for replying

      Hi Nico,
      So i should create another column in my tblAssignments and put what in there?
      Can you please give me a little bit more details as to what i should do?

      Comment

      • nico5038
        Recognized Expert Specialist
        • Nov 2006
        • 3080

        #4
        Yes, add a column for the Image (OLE-Object) and make sure (e.g. using an update query) that the correct image is filled before showing the form.

        When no updates are needed you can just create a tblImage holding two records (ImageTest en ImageDecision) with a key 1 and 2 and link it to tblAssignment in a query that's used for the form.

        This table might also be handy for the Update query to set the value of the Image field.

        Getting the idea ?

        Nic;o)

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          Nico is right. This is not an alternative solution, but an explanation of the problem for better understanding of the issue (Why Values in Unbound Form Controls do not Persist).

          BTW You can still use your original approach if you prefer, store a Yes/No type value in the table, just setting the image depending on the value stored. Nico's approach is better though (They normally are).

          I hope it helps.

          PS. Welcome to full member status :)
          Last edited by NeoPa; Jul 11 '10, 11:06 AM.

          Comment

          • TravelingCat
            New Member
            • Feb 2010
            • 82

            #6
            Thanks NeoPa, was i just a guest earlier?.. Anyway, before replying here i searched and i read since i'm new to ole objects, and i followed the steps that are listed here:
            Get help with your questions about Microsoft Access with our how-to articles, training videos, and support content.

            I created a column assignImage in tblAssignment, and have put a bitmap image, only in one line, so i could see it works first. On the form i've put a textbox and bound it to "assignImag e", but all i see is something like binary signs. How do i actually display the image on a form? Maybe the fact that it's a subform has significance..
            Thank you for your help

            Comment

            • nico5038
              Recognized Expert Specialist
              • Nov 2006
              • 3080

              #7
              Just place the image field (e.g. with drag and drop) from the table "fresh" on the form and Access will do the "translatio n".

              Connecting an unbound (or text) field will give the garbage you see.

              Nic;o)

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                Let's handle this point by point.
                1. Members of <32 posts are labeled as Newbie. When the 32 posts mark is reached the title switches to Member. This is not an attempt to be derogatory, but it helps moderators to take inexperience into account when dealing with the stretching of any rules.
                2. As a general rule, describing what you have done in the post, rather than simply linking to something similar, is likely to garner more interest from anyone with an interest in answering your question. My own attitude to such links, and similarly posts of type "My problem is in the attached database.", is that if someone cannot put the effort in to post what I need to see and make it available without my having to go to any lengths to find it, then I don't anticipate an easy ride dealing with that person, so I will often steer clear of such a thread. I'd rather spend my effort answering questions than trying to teach people how to ask them. That's handled in the FAQ.

                  Please understand that I say this not to criticise, but to give an insight into how this is perceived from the other side, which can help you to post your questions in such a way that they are more likely to be answered.
                3. The technical part of this question, how to display your image, is a bit of a deviation from the original thread. Sometimes this is closely enough related to cause little in the way of problems. One of the main reasons we try to encourage new questions to be posted in their own thread though, is that experts that have help to offer on one particular point, may have little idea about a new point (question) introduced. That is the case with me now. I have little experience with images, though a fair bit with the problems of continuous forms (The only suggestion I can think of would be to bind the [assignImage] field to an Image control rather than a TextBox).

                  In this case, you may get lucky as I know that Nico can probably help if he's still around, but generally I'd still encourage you to post a separate thread. You benefit, as most experts will not be looking at a thread with so many responses to find a new question to help with. The potential pool of responders is therefore much greater with a new thread. Others benefit too, as threads on a single subject generally prove a lot easier to read and understand than those that switch between problems.
                Last edited by NeoPa; Jul 12 '10, 12:49 PM.

                Comment

                • TravelingCat
                  New Member
                  • Feb 2010
                  • 82

                  #9
                  NeoPa,
                  1. Thanks for the explanation.
                  2. I never wanted to appear as someone who isn't willing to put effort into writing a post, on the contrary. I thought link would be easier, not to mention that i've described my steps anyway, so the link was more like a supplement rather than the core of the question. I figured posting all that text here would be redundant and too much. So.. my intentions were good)
                  3. For some reason i didn't think there might be a case someone would want to only know how to set the images and not also show them on a form, 'cause it was my intention to begin with. You are right, i should've written this in my subject. Since Nico is indeed still here i'll first ask him.
                  As to your suggestion, i don't believe image control can be bound to anything, but of course i'm just a newbie (not by your definition, but i am:) ), so i don't know.

                  Nico, i have to admit i feel pretty dumb by now..
                  How do i drag and drop an image field from the table? Do you mean in tblAssignment, literally point on the "Bitmap image" in the assignImage column and drag it to the form? It doesn't want to be dragged..

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32669

                    #10
                    Originally posted by TravelingCat
                    TravelingCat: I figured posting all that text here would be redundant and too much. So.. my intentions were good)
                    That does it for me. Intentions are pretty well all.
                    Originally posted by TravelingCat
                    TravelingCat: As to your suggestion, i don't believe image control can be bound to anything, but of course i'm just a newbie (not by your definition, but i am:) ), so i don't know.
                    I just checked, and you're right. There's probably a way to handle the Image control, but I expect it's still the right one to use. I'll leave you in Nico's more competent hands for further progress though.

                    Comment

                    • nico5038
                      Recognized Expert Specialist
                      • Nov 2006
                      • 3080

                      #11
                      In A2007/2010 you can use the "Add Existing Fields" button, else insert an image control and connect that with the field from the form's recordsource.

                      Nic;o)

                      Comment

                      • TravelingCat
                        New Member
                        • Feb 2010
                        • 82

                        #12
                        Nico, but HOW do i connect image control with the field? Since image control can't be bound
                        (i have office 2003)

                        Comment

                        • nico5038
                          Recognized Expert Specialist
                          • Nov 2006
                          • 3080

                          #13
                          You need to use the "bound" image control (has xyz in the icon)

                          Nic;o)

                          Comment

                          • TravelingCat
                            New Member
                            • Feb 2010
                            • 82

                            #14
                            Only it's called object frame and not image control, so i didn't even look at it before.
                            Thank you very much for your patience! It works now.

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32669

                              #15
                              Sorry. That was probably me misleading you.

                              The Bound Object Frame control refers to a control that handles bound OLE objects. In this case an image. I understand it's a little more flexible than a simple image control, as it handles anything that OLE can, but that includes an image.

                              Comment

                              Working...