UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Conditional Images, Access 2010    
 
   
vaughanmcd
post Mar 13 2018, 07:43 PM
Post#1



Posts: 31
Joined: 23-March 09
From: Auckland, NZ


HI All, I need to have a form display an image based on a query or code , How is the best way to do this?

I have a linked table with a field that contains the current time of a source update

eg 1:34:56 pm

If the form re query's and the time in the table with the time field is older than 5 minutes then display red
if the time is within 5 minutes then display green

and should i have the images in folder on the server or in the DB table?

Vaughan
Go to the top of the page
 
theDBguy
post Mar 13 2018, 08:40 PM
Post#2


Access Wiki and Forums Moderator
Posts: 72,422
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Is "green" or "red" an image or just a color? If just a color, perhaps you can just use Conditional Formatting.

Just a thought...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
tina t
post Mar 13 2018, 08:46 PM
Post#3



Posts: 5,419
Joined: 11-November 10
From: SoCal, USA


well, i use some color .bmp files in one of my dbs, and just made the bitmaps tiny, because you can set the SizeMode property, of an Image control or BoundObjectFrame control, to Stretch, so that the color takes up as much space as you need. and i use only four bitmaps, so i just put a tblColors in my frontend - one record for each of the four bitmaps.

i store a couple other image files in my frontend db: a signature file, and a logo file. so i break the "rule" a little bit - but i wouldn't store data/document files in an Access table.

hth
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
tina t
post Mar 13 2018, 08:48 PM
Post#4



Posts: 5,419
Joined: 11-November 10
From: SoCal, USA


QUOTE
If just a color, perhaps you can just use Conditional Formatting.

DBguy's solution is better, of course, wherever you can use it. i store my color files because my dbs (actually, my employer's) are A97 - prior to the introduction of conditional formatting.

hth
tina
This post has been edited by tina t: Mar 13 2018, 08:48 PM

--------------------
"the wheel never stops turning"
Go to the top of the page
 
vaughanmcd
post Mar 13 2018, 09:55 PM
Post#5



Posts: 31
Joined: 23-March 09
From: Auckland, NZ


Sorry to clarify the Green and Red are just Colored images to be use as indicators on a front end. I realize it may be easy to tell a form to set the back color but I was thinking If it is linked to images the I could do something more fancy like a green tick and a red cross.

My question is more about how the code would work to display the different images based on the conditions
Go to the top of the page
 
LPurvis
post Mar 14 2018, 08:06 AM
Post#6


UtterAccess Editor
Posts: 16,271
Joined: 27-June 06
From: England (North East / South Yorks)


Hi, just adding. / checking:

Is the form in question showing a single record or is in Continuous view (displaying multiple rows)?

Cheers

--------------------
Go to the top of the page
 
tina t
post Mar 14 2018, 02:35 PM
Post#7



Posts: 5,419
Joined: 11-November 10
From: SoCal, USA


i can't recall if you can use ConditionalFormatting to make a control Visible/Not Visible. if so, i'd just use that. if not, then yes, i'd use some simple code. sorry, to clarify, i think the easiest thing might be two controls to show the colors/images you want. then use an expression to compare the two time values you're working with. in code, i'd set a boolean variable, as

CODE
    Dim bln As Boolean

     bln = (OneTimeValue < OtherTimeValue - 5)
     Me!MyOneControl.Visible = bln
     Me!MyOtherControl.Visible = Not bln


the True/False expression is just an example; use whatever works as you want it to. and, btw, take note of Leigh's question, too. in a ContinuousForm, ConditionalFormatting is what you'll need, if it can give you Visible/Not Visible.

hth
tina
This post has been edited by tina t: Mar 14 2018, 02:36 PM

--------------------
"the wheel never stops turning"
Go to the top of the page
 
vaughanmcd
post Mar 14 2018, 04:32 PM
Post#8



Posts: 31
Joined: 23-March 09
From: Auckland, NZ


This will be a sub form with it indicating images on it, It will be the only thing on the form.

Go to the top of the page
 
LPurvis
post Mar 15 2018, 07:31 AM
Post#9


UtterAccess Editor
Posts: 16,271
Joined: 27-June 06
From: England (North East / South Yorks)


I don't want my comment to be a distraction, so if there is a single record on this subform, then Tina's given you a suggestion to making an imagine control visible or not for that single record.

If it was continuous, CF wouldn't have helped you a great deal, but there are ways. Not least of which, the ability to bind Image controls to a text path (which still feels slightly new to me, even though it was introduced in 2007.. maybe I'm just getting old :-p).

Cheers

--------------------
Go to the top of the page
 
vaughanmcd
post Mar 18 2018, 11:51 PM
Post#10



Posts: 31
Joined: 23-March 09
From: Auckland, NZ


Sorry I'm a bit lost, Can you clarify what the code would look like and where the code would go?
Would it go on the form with the images? or on a blank form and the images are then in a file.

I've attached the two images that may be used on the form.
Attached File(s)
Attached File  green_tick.jpg ( 61.39K )Number of downloads: 1
Attached File  red_corss.jpg ( 61.45K )Number of downloads: 0
 
Go to the top of the page
 
BananaRepublic
post Mar 19 2018, 06:42 AM
Post#11


Dungeon Cleaner
Posts: 1,512
Joined: 16-June 07
From: Banana Republic


Given that you are on Access 2010, I'd adapt Leigh's suggestion of binding the image control, which will also be much faster and easier to set up than conditional formatting.

The simplest way with minimum code would be to distribute those files with your FE (perhaps in the same folder or a subfolder).

Then on a standard module, you need a function:

CODE
Public Function GetImagePath() As String
  GetImagePath = CurrentProject.Path & "\"
End Function


Then on the query that is used for the form....

CODE
SELECT ...
  GetImagePath() & "<name of the image to display for that record>" As ImagePath
FROM yourTable


When you run the query, you can verify it's set up correctly by making sure that each record has the correct path to the image. So if a record should have a red cross, then the output might be something like "C:\path\to\your\frontend\redcross.bmp" while other records that should have a green tick, then.... "C:\path\to\your\frontend\greentick.bmp". You may need a "IIf()" in your query if it depends on some criteria on your record. For example, if it depends on a checkbox "Submitted", then it might look like this:

CODE
IIf([Submitted], GetImagePath() & "greentick.bmp", GetImagePath() & "redcross.bmp") AS ImagePath


Once that's all done, then all you have to do on your form is to set the image control's control source to "ImagePath", which now comes from the query.

HTH.

--------------------
Using Access BE over WAN is like running to your city library, ripping out pages from a book, running back home and scribble notes on it then run back and glue the pages back into the book in the library, all during a rush hour full of drunk drivers in middle of a horrible thunderstorm, and hoping nobody else has ripped out the pages you wanted.
Go to the top of the page
 
vaughanmcd
post Apr 2 2018, 07:13 PM
Post#12



Posts: 31
Joined: 23-March 09
From: Auckland, NZ


Thanks Banana Republic, Just one more thing.
With the query, What table would the query be looking at because the 2 images are in a local front end folder? or is the query just got code in it as in right click criteria and then build ?
Just not sure when I'm puting the code in the query.

Everything else I've done fine.

I will need an iff statement somewhere.

If time now is within 5 minutes the use green image otherwise use red image.

Thanks
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    20th June 2018 - 09:46 PM