473,394 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2. Set rs = Me.RecordsetClone
  3. Do While Not rs.EOF
  4. Select Case rs("assignType")
  5.     Case 1:
  6.     ImageText.Visible = True
  7.     Case 2:
  8.     ImageDecision.Visible = True
  9.     End Select
  10. rs.MoveNext
  11. Loop
  12.  
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
Jul 8 '10 #1

✓ answered by nico5038

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)

26 6001
nico5038
3,080 Expert 2GB
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)
Jul 8 '10 #2
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?
Jul 11 '10 #3
nico5038
3,080 Expert 2GB
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)
Jul 11 '10 #4
NeoPa
32,556 Expert Mod 16PB
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 :)
Jul 11 '10 #5
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:
http://office.microsoft.com/en-us/ac...005280225.aspx
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 "assignImage", 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
Jul 12 '10 #6
nico5038
3,080 Expert 2GB
Just place the image field (e.g. with drag and drop) from the table "fresh" on the form and Access will do the "translation".

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

Nic;o)
Jul 12 '10 #7
NeoPa
32,556 Expert Mod 16PB
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.
Jul 12 '10 #8
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..
Jul 12 '10 #9
NeoPa
32,556 Expert Mod 16PB
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.
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.
Jul 12 '10 #10
nico5038
3,080 Expert 2GB
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)
Jul 12 '10 #11
Nico, but HOW do i connect image control with the field? Since image control can't be bound
(i have office 2003)
Jul 12 '10 #12
nico5038
3,080 Expert 2GB
You need to use the "bound" image control (has xyz in the icon)

Nic;o)
Jul 12 '10 #13
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.
Jul 12 '10 #14
NeoPa
32,556 Expert Mod 16PB
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.
Jul 12 '10 #15
I have one more question for Nico, if i may
Your second message was "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", now i added this column but i don't know how to write the update query (when i manually set an image in the table it shows ok on the form). I tried
Expand|Select|Wrap|Line Numbers
  1. strImage = "C:\Documents and Settings\alinab\Desktop\T.bmp"
  2. CurrentDb.Execute "Update tblAssignments SET assignImage = " & strImage & " WHERE assignType = 1;"
  3.  
but i get "syntax error (missing operator) in query expression "C:\.....".
Can you please help me with this?
Jul 13 '10 #16
nico5038
3,080 Expert 2GB
My advise is to create first a tblImage holding with as key 1 (being the assignType) the first image, key for the second assigntype image, etc.

Next use:

Expand|Select|Wrap|Line Numbers
  1. UPDATE tblAssignments SET assignImage = DLOOKUP("assignImage","tblImage","assignType = " & tblAssignments.assigntype & ";"
  2.  

Yourerror message will be cause by the fact that the filename isn't embedded in single quotes.
so: SET assignImage = " & strImage & " WHERE
Should be: SET assignImage = '" & strImage & "' WHERE

Nic;o)
Jul 13 '10 #17
I did everything you said, and wrote this:
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.Execute "UPDATE tblAssignments SET assignImage = ' " & DLookup("assignImage", "tblAssignImages", "assignType = " & assignType) & ";"
(your code didn't compile, i added ) , and tried many code variations)
But now the error is syntax error in string in query expression "?/
I just can't make it work...
If you have any more suggestions i'll be very glad to hear.
Also when i checked in immediate window for
Expand|Select|Wrap|Line Numbers
  1. DLookup("assignImage", "tblAssignImages", "assignType = " & assignType)
i got this: ?/
!????????????????? ? ???h ? ?? 6 ( #  ? ? ?????????????????? and so on, not sure if it's normal..
Jul 13 '10 #18
NeoPa
32,556 Expert Mod 16PB
TravelingCat: I did everything you said, and wrote this:
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.Execute "UPDATE tblAssignments SET assignImage = ' " & DLookup("assignImage", "tblAssignImages", "assignType = " & assignType) & ";"
It seems to me that is not so far wrong.

The problem here appears to be that you applied instructions meant for two different situations into the same result. The single-quote (') that you added in is only required in the situation where you're setting a string value of the address of the image (which is not the case here). In that case it would need one leading into the string and another to mark the end of it.

In this case, because your are not using the string directly as Nico was, but are having first to describe it in VBA so that it can then be passed as SQL to .Execute, it is a little more tricky. Please try the following to see if it works for you :
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.Execute "UPDATE tblAssignments " & _
  2.                   "SET assignImage = DLookup('assignImage'," & _
  3.                                             "'tblAssignImages'," & _
  4.                                             "'assignType=' & [assignType] & ');"
Jul 13 '10 #19
Wait..was i supposed to put Nico's update string in image's control source and not in vba? That's why i didn't understand the "update" without db.Execute.. If so, it still isn't working.
And your string copied exactly also gives syntax error in string. I'm gonna shoot myself in a while...
Jul 13 '10 #20
NeoPa
32,556 Expert Mod 16PB
Did you copy the string or the code? I'm a little confused.

Try to explain exactly what you did more clearly.
Jul 13 '10 #21
I've put the code you suggested into vba onLoad event -> syntax error.
Then i tried to put Nico's code -
Expand|Select|Wrap|Line Numbers
  1. UPDATE tblAssignments SET assignImage = DLOOKUP("assignImage","tblImage","assignType = " & tblAssignments.assigntype & ";"
into the control source of the Bound Object Frame control on the form, and it also didn't work (i had to put = before the code line and it messed up the syntax).
What is the right way?
Jul 13 '10 #22
NeoPa
32,556 Expert Mod 16PB
Well, you can't bind an object to an action query that's for sure.

Is the database set up with the referred to fields available in a table of that name?
Jul 13 '10 #23
nico5038
3,080 Expert 2GB
My SQL is created to run in the query editor.
Thought you needed a once off job.
When you save that query you can execute that instead of the string (Looks like: docmd.execute ("qryUpdate") ), else repace all " by ' and embed the entire statement between double quotes (")

Nic;o)
Jul 13 '10 #24
NeoPa
32,556 Expert Mod 16PB
I think the OP found that you'd left off the closing parenthesis Nico. Other than that, that was what I posted (at least so I thought) in post #19, but the OP reports that as failing. It's not clear if it was copied correctly though, and/or entered into the procedure correctly.
Jul 13 '10 #25
Guys... i can't believe my eyes, but it finally works! It really was so easy, if only Nico would have elaborated on that crutial post for a dummy like myself:) All i had to do was to create the simplest update query:
Expand|Select|Wrap|Line Numbers
  1. UPDATE tblAssignments INNER JOIN tblAssignImages ON tblAssignments.assignType = tblAssignImages.assignType SET tblAssignments.assignImage = [tblAssignImages].[assignImage];
and run it in vba - CurrentDb.Execute ("qryAssignType"). I'm new to this, and i get by with basic stuff like recordsets, basic functions. I guess update query is also basic, but i'm still learning.
That should've taken 5 minutes..
Thanks you both very much for your help and the time you've spent on this thread, it can now be closed.
Jul 14 '10 #26
NeoPa
32,556 Expert Mod 16PB
Hi TC. Pleased you got it working.

We don't close threads as such, but if you'd like to select a post as the Best Answer for anyone else finding the same problem, then that will indicate no further solutions are necessary.
Jul 14 '10 #27

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: RugbyTravis | last post by:
I want to have a list that is horizontal and each <li> has different images. I also want them to change on hover. I want the words to be below the images as well. Anyone of you styles gurus have...
0
by: Ryan Liu | last post by:
Hi, I want to validate the cell value before commit it -- changing the cell from edit mode(text box, DateTimePicker) to view mode. This happens when I click on other cell. Which event I can...
1
by: esroinc | last post by:
By creating an event that fires when I click on a cell, I am able to obtain the coordinates of that cell, but I have not been able to get the data or value in that cell. cellCoordinates =...
9
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell as tempstring =...
3
by: vj | last post by:
how to change images based on action. Even clicking changed images should do respective actions. and while displaying only one image at a time sholud get displayed. I am using three images for a...
0
by: suresh_punniyakkodi | last post by:
Hellow Friends, I have one doubt, please help me... In Excel, i have lot of rows and coloumns, i need to read all cell values with in rows and coloumn limit... At the time...
4
by: CGatto | last post by:
Hello, Just wondering if anyone has ever managed to find a way to have a datagridviewimagecolumn display different images on different rows depending on some data element in the row. Our...
2
by: cpStar | last post by:
I have a report grouped by a location field. In the detail section it shows several columns such as 1st name, last name, city, st, zip & company name. My user would like his report sorted based on...
4
by: ravir81 | last post by:
Hi, I am currently working on excel validation using Perl. I am new to Excel validation but not for Perl. I have a question regarding one of the validation. Could anyone please tell me how to get...
5
by: dave816 | last post by:
Sorry for the Excel question in an Access forum...................I don't see an Excel forum and there's probably a reason for that but figured I'd give this a shot anyway. Again sorry, delete if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.