Problem with dynamic image in MS Access report (1 Viewer)

Monardo

Registered User.
Local time
Today, 17:41
Joined
Mar 14, 2008
Messages
70
Hello,

I have a report for printing labels on a grid of let's say 3 by 6 on A4 paper. These are peel-off labels, which can be printed either full sheet or just 1, depending on needs.

The report's Record Source is a query, which contains always 18 records (to cover 3x6 grid), and 3 columns: [ID] (1-18), [LabelText] and [Path]. Out of these 18 records sometimes all 18 LabelText and Path are populated, but sometimes only first few (and the rest is empty "" ), but also it could be that say first 4 are empty, then 6 have data and the rest 8 are empty. ID is always populated with numbers 1 to 18. This is done so that labels on A4 are not wasted.

Each printed label should contain different image based on file path given in column [Path]. This is achieved with Dental On Format event

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
   Me.Image0.Picture = Me.path
End Sub

All works with a problem.

  1. If all 18 labels are filled, all is correct
  2. If say first 3 records are filled, then first 3 labels get correct Image, but all the rest of 15 labels also get last image (from label 3)
  3. If say first 3 records are empty and next 3 records have data and the rest is empty, then first 3 labels have no image (as it should be) labels 4-6 have correct image and the rest again get last image (from label 6)
I tried many different "If/Else" options in On Format event, but always get same result. There must a simple solution, but I am not seeing it.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:41
Joined
May 7, 2009
Messages
19,169
maybe something like:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
   Me.Image0.Picture = iif(IsNull(Me.path), "", Me!path)
End Sub
 

Monardo

Registered User.
Local time
Today, 17:41
Joined
Mar 14, 2008
Messages
70
maybe something like:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
   Me.Image0.Picture = iif(IsNull(Me.path), "", Me!path)
End Sub

Well, the [path] in query is never NULL, it's either "C:\img\1.png" or "", specifically to accommodate Me.Image.Picture attribute.
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:41
Joined
Sep 21, 2011
Messages
14,044
Well, the [path] in query is never NULL, it's either "C:\img\1.png" or "", specifically to accommodate Me.Image.Picture attribute.
So test it's length? :(
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:41
Joined
May 7, 2009
Messages
19,169
you are saying there are some "fields" are empty?
then test that "field".

Me.Image0.Picture = iif(IsNull(Me.theFieldToCheck), "", Me!path)
 

Monardo

Registered User.
Local time
Today, 17:41
Joined
Mar 14, 2008
Messages
70
you are saying there are some "fields" are empty?
then test that "field".

Me.Image0.Picture = iif(IsNull(Me.theFieldToCheck), "", Me!path)

To clarify bit more:

The query output looks like this

Code:
ID        LabelText             Path
1         ""                    ""
2         ""                    ""
3         "N001"                "C:\img\N001.png"
4         "N002"                "C:\img\N002.png"
5         ""                    ""
...       ""                    ""
...       ""                    ""
18        ""                    ""

The Report Should look like this:

Code:
Empty      Empty      Img1
Img2       Empty      Empty
Empty      Empty      Empty
Empty      Empty      Empty
Empty      Empty      Empty
Empty      Empty      Empty

But looks like this

Code:
Empty      Empty      Img1
Img2       Img2        Img2       
Img2       Img2        Img2       
Img2       Img2        Img2       
Img2       Img2        Img2       
Img2       Img2        Img2

And also I don't really need to check for anything, path is already "" to account for

Code:
Me.Image0.Picture = ""
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:41
Joined
May 7, 2009
Messages
19,169
goto design view of your report.
on page setup, Columns, choose Across, then down.
 

Monardo

Registered User.
Local time
Today, 17:41
Joined
Mar 14, 2008
Messages
70
Well, thanks for your time, especially @arnelgp.

Could not solve the problem programmatically, but I solved it by cheating. I just created blank.png with plain white background and I added path to query, where it should be empty.

Still would be interesting if there is VBA solution.
 

Users who are viewing this thread

Top Bottom