If Statement with multiple veribals (1 Viewer)

weilerdo67

New member
Local time
Yesterday, 19:44
Joined
Aug 2, 2019
Messages
3
Hi, I think im doing this wrong and Im hoping someone can help me. I have a report that I want to have an image show depending on the value of a field. ON the report I have a field called AvgOfTemp and what I need is if the temp is greater the 100 show img36 if the temp is between 32 and 100 show img32 and finally if the temp is below 32 show img40. I am new to coding and somewhat lost. this is the statement I have but it is only showing img40 no matter what the value in AvgOfTemp is. Any help would be greatly appreciated.


If Me.AvgOfTemp < 100 Then

img32.Visible = True
img36.Visible = False
Else

img32.Visible = False
img36.Visible = True
End If

If Me.AvgOfTemp < 32 Then
img40.Visible = True
img32.Visible = False
Else
img40.Visible = False
img32.Visible = True
End If
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:44
Joined
Oct 29, 2018
Messages
21,499
Hi. Welcome to the forum! Just curious first, where are the images coming from? Are they stored in a table or at least the path to them are stored in a table?
 

MrHans

Registered User
Local time
Today, 04:44
Joined
Jul 27, 2015
Messages
147
Hi,

How about

If me.AvgOfTemp < 32 then
Image below 32 goes here
Elseif me.AvgOfTemp > 100 then
Image above 100 goes here
Else
Image between 32 and 100 goes here
End if
 

weilerdo67

New member
Local time
Yesterday, 19:44
Joined
Aug 2, 2019
Messages
3
Hi, Thanks for the replies


I tried this and its showing all of the images. Is it because I dont have a False value?



If Me.AvgOfTemp < 32 Then
img40.Visible = True
ElseIf Me.AvgOfTemp > 100 Then
img36.Visible = True
Else
img32.Visible = True
End If


The images are located in the report it's self, not in a table or stored anywhere other the the report. I hope that helps
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:44
Joined
May 7, 2009
Messages
19,246
add the code to the Detail section's Format event:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
[img36].Visible=False
[img32].Visible=Fase
[img40].Visible=False
If Me.AvgOfTemp < 32 Then
    img40.Visible = True
ElseIf Me.AvgOfTemp > 100 Then
    img36.Visible = True
Else
    img32.Visible = True
End If
End Sub
[/code]
 

MrHans

Registered User
Local time
Today, 04:44
Joined
Jul 27, 2015
Messages
147
Yeah you need to make the others invisible in that case.

Img1.visible = true
Img2.visible = false
Img3.visible = false

In the next elseif
Img1.visible = false
Img2.visible = true
Img3.visible = false

In the else
Img1.visible = false
Img2.visible = false
Img3.visible = true

Edit, yeah like Arnel shows :)
 

weilerdo67

New member
Local time
Yesterday, 19:44
Joined
Aug 2, 2019
Messages
3
Ok, that got me closer. It works for the >100 and the >32 it shows those correctly now but the <32 is still showing the wrong image. Here is the code I used from arnelgp


Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)



[img36].Visible=False

[img32].Visible=False

[img40].Visible=False

If Me.AvgOfTemp < 32 Then

img40.Visible = True

ElseIf Me.AvgOfTemp > 100 Then

img36.Visible = True

Else img32.Visible = True

End If
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:44
Joined
May 7, 2009
Messages
19,246
the image for < 32 should be img40, check the image control if this is correct image.

or you reverse the logic of the IF statement:

If >100 then

ElseIF > 31

Else

End If
 

deletedT

Guest
Local time
Today, 03:44
Joined
Feb 2, 2019
Messages
1,218
I know it's not the answer to your question but I never use several images in a form or report. Embedded images makes my application grow in size and consequently slower.


I normally use a linked image and change the path to the image in load or open events.
 

Users who are viewing this thread

Top Bottom