Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Sep 2020
    Posts
    10

    Shrink Empty Picture Field in Report

    Hello All,
    In my report for wild animals, at the start of the detail section there is a picture field for a distribution map [DistributionMap].The map is linked to the field when a map exists, but some animals don't have a map. Picture fields don't have a 'can shrink' property. Is there another way to remove the field when it is null, so the text shifts up? If using code, where would I put it? Thanks for listening!


    Cheers Helen

  2. #2
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    629
    Assuming your using an image control, have you tried setting the height and width properties with code? I would try the oncurrent event with something like

    Code:
    If isnull(YourImageFieldName) then
    me.YourImageControlName.Height = 0
    else
    me.YourImageControlName.Height = 2010 (or whatever height you want)
    end if
    obviously substitute your names and dimensions in above.

    it may be tricky to determine the height you want so I would try doing a debug.print of the height property.
    I believe it is measured in twips (1440 twips = 1")

    edit: I hope your not using an attachment field.
    If this helped, please click the star at the bottom left and add to my reputation- Thanks

  3. #3
    Join Date
    Sep 2020
    Posts
    10
    Hi moke123 and thanks for your response.
    Yes, I am using an attachment field, and I suppose that is why your code failed.
    This is the code I put in On Attachment Current:

    Private Sub attDistributionMap_AttachmentCurrent()
    If IsNull(DistributionMap) Then
    Me.AttDistributionMap.Height = 0
    Else
    Me.AttDistributionMap.Height = 4252
    End If
    End Sub


    Is there a problem with using the attachment field, and if so, what should I use? Each map is a jpeg of 150-200 kb. If I select Image in design view, it wants me to insert the image while still in design view, but I insert a different map for every animal.
    Thanks again, Helen

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    7,501
    OnAttachmentCurrent
    Is that the name of a procedure you wrote? If not, I think the syntax is NameOfYourAttachmentField.AttachmentCurrent.
    FWIW, I have no idea what happens if there is no attachment in a field when you navigate to a record, mainly because I would not use an attachment field. Causes too much db bloat and they are a type of multi value field IIRC, which is another thing I wouldn't use. What I would use is a table with file paths to the file and an image control. However I don't see from your last post exactly why you're stuck at the moment - unless it is OnAttachmentCurrent because the error message doesn't seem to have anything to do with resizing.

    BTW, you just close the file dialog when you drop the control (image control) onto your form and then when the control is highlighted in design view, just set the picture type to "linked" on property sheet Format tab. After that, you can set the control source property in code - maybe in the Current event.
    Last edited by Micron; 10-15-2020 at 04:57 PM. Reason: clarification
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    "Everyone has a photographic memory; some just don't have film." Steven Wright

  5. #5
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    629
    I, like Micron and many experienced developers, never use attachment fields for a variety of reasons.
    I find it much easier to use an image control and store the path to an image as text.
    There are several methods to populate the image control to chose from.
    The code I provided simply changes the height of the control.

    Very often I'll use a default "No Image Available" image.
    Code:
    Me.Image1.Picture = Nz(PathToImage,PathToNoImage)
    If this helped, please click the star at the bottom left and add to my reputation- Thanks

  6. #6
    Join Date
    Sep 2020
    Posts
    10
    Thanks Micron and moke123.
    Micron, On Attachment Current was the closest I could find to the event you suggested; On Current wasn't listed in the Events.
    Just a comment about bloat; it's probably not a critical issue for me because the database is for home use (for my use only), and I don't expect it to grow too much.
    When I said the code failed I probably used incorrect terminology. It didn't fail but it didn't succeed, that is, the attachment frame didn't disappear or collapse in size when there was no image.
    I'll post again when I've tried using image control instead of a linked attachment field.
    Thanks again to you both for all the ideas!
    Helen

  7. #7
    accesstos's Avatar
    accesstos is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    335
    Hi all!

    Helen,
    There is no way to change the height of the Detail section of a report "on the fly". This is a feature of a web page and, if you want, you can create a HTML file using VBA and display it in a browser as report.

    I made a sample database to demonstrate how it works.
    Check the attachment, inspect the contents of tblHTML and modHTML objects, and let me know if you get any errors at opening the HTML file via the relevant button of the "frmAnimals" form.
    If fail to open automatically, locate the file "animals.html" in the "Animals" folder and open it manually with any browser exept IE.

    I hope this helps!

    Cheers,
    John
    Attached Files Attached Files

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    7,501
    I see what the confusion is. You're using the name from the property sheet. I'm using the vba syntax. Look at your code for that event - it is like what I wrote.
    Attachment3_AttachmentCurrent
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    "Everyone has a photographic memory; some just don't have film." Steven Wright

  9. #9
    Join Date
    Sep 2020
    Posts
    10
    Hi there Micron, moke123 and John,
    Micron and moke123, I replaced my attachment field with an image field as you suggested, and stored the path to the image in the database.
    The name of my control is ctlSpeciesMap. The control source is SpeciesMap. Picture Type is Linked. The image doesn't have Event "On Current", so I put the following Event Procedure in "OnCurrent" for the Detail section of the report:
    Private Sub Report_Current()
    If IsNull(Me![SpeciesMap]) Then
    Me.ctlSpeciesMap.Visible = False
    Me.ctlSpeciesMap.Top = 0
    Me.ctlSpeciesMap.Height = 0
    Else
    Me![ctlSpeciesMap].Picture = Me![SpeciesMap]
    Me.ctlSpeciesMap.Top = 10
    Me.ctlSpeciesMap.Height = 100
    Me.ctlSpeciesMap.Visible = True
    End If
    End Sub
    It appeared to have no effect at all: an empty image field doesn't disappear. Can you see where I've gone wrong, or do you have anymore suggestions?
    John, Thanks very much for all your work in setting up the little database. I hope to have a play with it tonight. I'm not sure that I understand you. Are you saying it is impossible to shrink an empty image field for a paper print out?
    Thanks again for your help, Helen
    Last edited by The Brown Maggot; 10-18-2020 at 04:35 PM. Reason: typos

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    7,501
    If you remain stuck, I would attempt to see what could be done. A lot depends on the design of your report and whether or not you could accept an altered layout. One possible solution is that the image control is in a sub report, which AFAIK, should shrink if there is no data or shrink to fit an image control that has already been down-sized. Then there are events for reports that are not listed on a report property sheet but I would think that the Format event for the detail section is there, and that is one that I would expect would resize the section. At this point, I'm also wondering if the instances of a single image control will perform as we expect. If it was bound, I'd say yes. Then there is the fact that some report events only work in a specific view (i.e. preview or report view but not both) so I'm sure you can appreciate that there are mucho variables at play.

    So I think there are a lot of possibilities but I confess that I'm too lazy to build a db, set up a folder of images, link them all in a table, build a report based on some arbitrary data, etc. etc. So as I said if you remain stuck I'm sure that I or someone who beats me to it would try to work with your db, its report, and a zipped folder of just a few images.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    "Everyone has a photographic memory; some just don't have film." Steven Wright

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    7,501
    I decided to google this topic. In less than 2 minutes I found this (and could not help but notice that it uses the Detail section Format event as I mentioned.

    http://www.ammara.com/access_image_f...rt_shrink.html
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    "Everyone has a photographic memory; some just don't have film." Steven Wright

  12. #12
    Ajax is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    8,639
    I was just about to suggest use the format event for the relevant section. But an image control also does not have can grow/shrink properties.

    having done your stuff with the image control you then need to adjust all controls below it in that section, then adjust the section height - so perhaps something like this (I've simplified your code)

    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    
    Const imageheight=100 'note this is very small - there are 1440 twips to an inch - so this is less than 10th inch
    
    
    
        Me.ctlSpeciesMap.Visible = IsNull(Me.[SpeciesMap])=false 'if SpeciesMap is a string you may need to use nz(SpeciesMap,"")<>""
        Me.ctlSpeciesMap.Height = imageheight * abs(ctlSpeciesMap.Visible) 'will set height to 0 if control not visible and imageheight if it is
        me.textboxbelow.top=ctlSpeciesMap.top + ctlSpeciesMap.height+60 '60 just to provide a bit of space between controls
        me.nexttextbox.top=me.textboxbelow.top+me.textboxbelow.height+60
        ...
        ...
        me.detail.height=0 'this will reduce the detail section height to the minimum possible (i.e. the top+height of the lowest control in the section)
    
    End Sub
    comments on your code
    Me![ctlSpeciesMap].Picture = Me![SpeciesMap] - just bind the control, no need to assign or not assign.
    Me.ctlSpeciesMap.Top = 10 - no need to change this
    Me.ctlSpeciesMap.Height = 100 required but set as a constant (and way too small)
    Me.ctlSpeciesMap.Visible = True - see alternative calculation

    There is another event you may need to consider -
    Detail_Retreat() to reset values between each detail section, but I suspect not required in this example

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    7,501
    But an image control also does not have can grow/shrink properties.
    True, but the code link I posted doesn't try to use such a property. It does a resize on the control though. I do wonder about this line in that code though

    If Len(strPath) > 0 And Len(Dir(strPath)) > Then

    greater than what? Looks like a boo-boo to me.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    "Everyone has a photographic memory; some just don't have film." Steven Wright

  14. #14
    accesstos's Avatar
    accesstos is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    335
    Quote Originally Posted by The Brown Maggot View Post
    Hi there Micron, moke123 and John,
    Micron and moke123, I replaced my attachment field with an image field as you suggested, and stored the path to the image in the database.
    The name of my control is ctlSpeciesMap. The control source is SpeciesMap. Picture Type is Linked. The image doesn't have Event "On Current", so I put the following Event Procedure in "OnCurrent" for the Detail section of the report:
    Private Sub Report_Current()
    If IsNull(Me![SpeciesMap]) Then
    Me.ctlSpeciesMap.Visible = False
    Me.ctlSpeciesMap.Top = 0
    Me.ctlSpeciesMap.Height = 0
    Else
    Me![ctlSpeciesMap].Picture = Me![SpeciesMap]
    Me.ctlSpeciesMap.Top = 10
    Me.ctlSpeciesMap.Height = 100
    Me.ctlSpeciesMap.Visible = True
    End If
    End Sub
    It appeared to have no effect at all: an empty image field doesn't disappear. Can you see where I've gone wrong, or do you have anymore suggestions?
    John, Thanks very much for all your work in setting up the little database. I hope to have a play with it tonight. I'm not sure that I understand you. Are you saying it is impossible to shrink an empty image field for a paper print out?
    Thanks again for your help, Helen
    Helen,

    Please forgive me and ignore my reply.
    I thought that it's possible to set the height of Detail section only in design mode. I was wrong.

    You taught me something today.
    Thanks all!

  15. #15
    Ajax is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    8,639
    True, but the code link I posted doesn't try to use such a property. It does a resize on the control though.
    I know, I started my response before you had posted, and my point was more about needing to move the other controls up to emulate 'can shrink'

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 19
    Last Post: 05-23-2020, 05:07 PM
  2. Replies: 4
    Last Post: 02-01-2019, 08:39 AM
  3. Replies: 8
    Last Post: 12-17-2017, 12:33 PM
  4. Replies: 17
    Last Post: 07-15-2014, 06:17 AM
  5. Replies: 1
    Last Post: 10-10-2012, 12:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums