graphic issue (1 Viewer)

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
I have a report that has a graphic field which based on a value in an unbound field. The code works.
But when I put that code on open of the report, no value get put in the unbound field. If I put that same code in a command button, it works fine.

So, I'm guessing some kind of time issue?

Here is the code: If [Mdid] = "ABC123" Then [backgroundpath] = "\\Reportbackgrounds\ABCreport.png"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:48
Joined
May 7, 2009
Messages
19,248
put the code on the Load event.
 

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
Sorry, it is on Load
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:48
Joined
Feb 28, 2001
Messages
27,195
Check carefully for report events. There are circumstances when they don't fire as a matter of design. The biggest differences are between Report View and Print Preview, which have a complementary set of events.
 

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
Both Report View and Print Preview are doing the same. Nothing.
 

isladogs

MVP / VIP
Local time
Today, 15:48
Joined
Jan 14, 2017
Messages
18,241
Are you using an image control?
Code:
Me.Image0.Picture = "Path to your file.png"

If so, using the Report_Load event, it should work in both Print Preview and Report View
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:48
Joined
Oct 29, 2018
Messages
21,477
Since you're using an If statement, just wondering how many different images do you need to show?
 

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
Are you using an image control?
Code:
Me.Image0.Picture = "Path to your file.png"

If so, using the Report_Load event, it should work in both Print Preview and Report View
But my code works in a command button. What is different about what you are suggesting?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:48
Joined
Feb 28, 2001
Messages
27,195
Command buttons (button click events), Load events, Print events, and Format events are ALL events. From a strict programming sense, there is no difference in the way they are called (unless it is one of the cases that allows a Cancel parameter). The ONLY practical difference is when those events fire.

But I suspect that there is one more event that maybe you need to consider. In the Report_Open event, not all controls are available because the "container" that holds the details of the report has just been opened. Some security-related decisions can be made regarding the report as a whole, but the individual controls aren't available yet. They haven't been loaded. (And Form_Open is one of those events that allow a Cancel.)

In the Report_Load event, controls have been loaded and should be available. But the question is, WHERE is this control? In a report header? Page header? Group header? Detail area? Because it MIGHT be that you need to run that code in the Format event of the section that contains the desired control.
 

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
Thanks for the explanation. The control is in the detail area.
 

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
Command buttons (button click events), Load events, Print events, and Format events are ALL events. From a strict programming sense, there is no difference in the way they are called (unless it is one of the cases that allows a Cancel parameter). The ONLY practical difference is when those events fire.

But I suspect that there is one more event that maybe you need to consider. In the Report_Open event, not all controls are available because the "container" that holds the details of the report has just been opened. Some security-related decisions can be made regarding the report as a whole, but the individual controls aren't available yet. They haven't been loaded. (And Form_Open is one of those events that allow a Cancel.)

In the Report_Load event, controls have been loaded and should be available. But the question is, WHERE is this control? In a report header? Page header? Group header? Detail area? Because it MIGHT be that you need to run that code in the Format event of the section that contains the desired control.
I've tried to put the code every where, no luck.
 

June7

AWF VIP
Local time
Today, 06:48
Joined
Mar 9, 2014
Messages
5,475
Why in VBA and not expression in Image Control ControlSource property?

What do you mean by "graphic field"? What control are you using to display images?
 

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
Why in VBA and not expression in Image Control ControlSource property?

What do you mean by "graphic field"? What control are you using to display images?
I'm using an image and the source is an unbound field with the path of the image file.
And i have an IF statement that fills in that image path based on value from another field.
 

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
Are you saying I can put my IF statement in the image ControlSource property?
 

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
Can you show me an example of an IF statement using my info?
 

June7

AWF VIP
Local time
Today, 06:48
Joined
Mar 9, 2014
Messages
5,475
It would be IIf() function.
=IIf([Mdid] = "ABC123", "\\Reportbackgrounds\ABCreport.png", Null)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:48
Joined
May 7, 2009
Messages
19,248
can you post a sample db.
maybe you can use Query and change the image Path using the Query:

select [Mdid], Switch( [Mdid] = "ABC123", "\\Reportbackgrounds\ABCreport.png", [Mdid] = "Code2", "Image2", [Mdid] = "Code3", "Image3", [Mdid] = "Code4", "Image4", [Mdid] = "Code5", "Image5") As ImagePath from yourTable;

see Query1 on the sample db.
see sampleReport.

first extract all files on Same folder.
 

Attachments

  • Documents.zip
    70.6 KB · Views: 50

kitty77

Registered User.
Local time
Today, 10:48
Joined
May 27, 2019
Messages
712
It would be IIf() function.
=IIf([Mdid] = "ABC123", "\\Reportbackgrounds\ABCreport.png", Null)
Yes, that worked. How can I add multiple IF's? If "DEF123" = another image path, etc...
Also, if it does not meet any of them, then some default path.

Thanks!!!
 

Users who are viewing this thread

Top Bottom