admin管理员组

文章数量:1129021

I have an access database where I have checkboxes for 5 items

These checkboxes all relate to a different image

I would like these images to appear in a report, hiding those which are not ticked and also hiding the location to make the appearance look better.

for example

image1 = true
image2 = true
image3 = false
image4 = false
image5 = true

I have been able to hide the images, but I would prefer for them to be hidden completely

I would like to see Image1 | Image2 | Image4 | Image5

Rather than Image1 | Image2 | | | Image4 | Image5

I have an access database where I have checkboxes for 5 items

These checkboxes all relate to a different image

I would like these images to appear in a report, hiding those which are not ticked and also hiding the location to make the appearance look better.

for example

image1 = true
image2 = true
image3 = false
image4 = false
image5 = true

I have been able to hide the images, but I would prefer for them to be hidden completely

I would like to see Image1 | Image2 | Image4 | Image5

Rather than Image1 | Image2 | | | Image4 | Image5

Share Improve this question edited Jan 8 at 14:35 Ian asked Jan 8 at 14:33 IanIan 11 bronze badge New contributor Ian is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1
  • According to the desired results layout image4 should be true. – Shahram Alemzadeh Commented Jan 9 at 14:51
Add a comment  | 

1 Answer 1

Reset to default 0

It sounds like you want to keep a running total of where to position the image, and then adjust that at the same time that you show/hide the images. A crude version could be as follows:

Const imgStart AS Double = <SomeValue>
Const imgSpacing AS Double = <OtherValue>
Dim imgLeft AS Double

imgLeft = imgStart

With picImage1
    If image1 Then
        .Visible = True
        .Left = imgLeft
        imgLeft = imgLeft + .Width + imgSpacing
    Else
        .Visible = False
    End If
End With

With picImage2
    If image2 Then
        .Visible = True
        .Left = imgLeft
        imgLeft = imgLeft + .Width + imgSpacing
    Else
        .Visible = False
    End If
End With

With picImage3
    If image3 Then
        .Visible = True
        .Left = imgLeft
        imgLeft = imgLeft + .Width + imgSpacing
    Else
        .Visible = False
    End If
End With

With picImage4
    If image4 Then
        .Visible = True
        .Left = imgLeft
        imgLeft = imgLeft + .Width + imgSpacing
    Else
        .Visible = False
    End If
End With

With picImage5
    If image5 Then
        .Visible = True
        .Left = imgLeft
        imgLeft = imgLeft + .Width + imgSpacing
    Else
        .Visible = False
    End If
End With

This uses imgLeft to track what the left position of the next image should be, and increments it by the Image Width, plus a spacer, each time it makes an image visible.

You could refine it using a loop to track things, and also by adding a vertical component: i.e. if imgLeft + .Width is greater than your desired page-width, then you increase an imgHeight variable and reset imgLeft = imgStart to begin another row of images

本文标签: vbaHiding Images In MS Access ReportStack Overflow