Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Image control not shrinking

Posted on 2012-03-16
6
Medium Priority
?
343 Views
Last Modified: 2012-05-12
My report is printing all images the same height even though my VBA code adjusts the height for each one. Here are the details.

My report contains a subform which contains an image control. It links to a graphic file. The filename changes for each record in report. In the subform's Detail_Format procedure, VBA code adjusts the height and width properties of the image based on values (in inches) stored in text boxes in the subform. The textboxes are bound to two fields in the underlying table that stores the desired height and width of the image when it prints. My report has images with different desired height and width values. However, they are all 5 inches (i.e., 7200 twips) tall in the report printout. There is a lot of white space below the small images. For example, a 3-inch high image has two inches of white space below it.

I have confirmed that the Shrink property is set to Yes for the image control, subform control, detail section for the subform (where the image control is located), and the section in the main form where the subform is located.

The code is below for the subform's detail_format event.
--------------------------------
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    Const clngTwipsPerInch As Long = 1440
    Const clngMaxImageWidth As Long = 9360 'in twips, 9360 twips = 6.5 inches
    Const clngMaxImageHeight As Long = 9360 'in twips, 9360 twips = 6.5 inches
   
    Dim lngImageWidth As Long 'in twips
    Dim lngImageHeight As Long 'in twips
    Dim dblImageRatio As Double

    lngImageWidth = clngTwipsPerInch * Me.txtStemImageWidth
    lngImageHeight = clngTwipsPerInch * Me.txtStemImageHeight

    'If the image is too wide for the page, then shrink it to fit.
    If lngImageWidth > clngMaxImageWidth Then
        dblImageRatio = clngMaxImageWidth / lngImageWidth
        lngImageWidth = dblImageRatio * lngImageWidth
        lngImageHeight = dblImageRatio * lngImageHeight
    End If

    'If the image (even after shrinking for width) is too long, then shrink to fit.
    If lngImageHeight > clngMaxImageHeight Then
        dblImageRatio = clngMaxImageHeight / lngImageHeight
        lngImageWidth = dblImageRatio * lngImageWidth
        lngImageHeight = dblImageRatio * lngImageHeight
    End If

    Me.imgStemGraphic.Width = lngImageWidth
    Me.imgStemGraphic.Height = lngImageHeight

    Me.imgStemGraphic.Picture = Me.txtItemFileName
   
    Debug.Print "Item " & Me.Parent.ItemID & _
        ", Seq = " & Me.Parent.txtItemSeq & _
        ",  Image = " & Me.imgStemGraphic.Width & _
        " W   x  " & Me.imgStemGraphic.Height & " H"

End Sub
----------------------------------

Here is the output of the debug.print statement above.
--------------------------
Item 700012, Seq = 34.,  Image = 5573 W   x  4176 H
Item 700012, Seq = 34.,  Image = 5573 W   x  4176 H
Item 700024, Seq = 96.,  Image = 9360 W   x  7369 H
Item 700024, Seq = 96.,  Image = 9360 W   x  7369 H
Item 700024, Seq = 96.,  Image = 9360 W   x  7369 H
---------------------------

This report contains two images. Each of the two item records has one image. I don't know whether this is relevant, but notice that the two item records are formatted a different number of times. The first one is formatted twice whereas the second one is formatted three times.

So, why does Access add white space below each graphic so that they are all 5 inches (7200 twips) high--even though their height property values differ?
0
Comment
Question by:gordonwwaugh
  • 3
  • 3
6 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37730517
This is why I simply set the size of the Image control to be a good size for all images. (and to fit nicely in the report)
Then I just set the sizemode property of the image control to "Zoom".
(to keep the aspect ratio for each image)
This way a 11X17 image is the same size on the report as a 5X7 image.

I also (if possible and practical), try to define a resolution and size for the images.
In other words, people don't just "Take Pictures" and give them to me,...
I tell them that the Pic should be at least 300dpi, ...etc.
Then, (if needed) the images are re-sized in a graphics application, so that they are all "roughly" the same Size, regardless of the resolution. (Again, if this is practical/possible)

(To me at least) Trying to adjust the image size dynamically at runtime (as you are trying to do here) is just not worth the trouble IMHO...

Let's see what other Experts may post...


JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37730553
There are just too many factors that might contribute to this issue:...

Does this work when you "keep it Simple" and just do this in a single Report?

For me it is extremely difficult to troubleshoot issues like this without a sample dB.
Sample database notes:
1. Back up your database(s).
2. Combine the front and back ends into one database file.
3. Remove any startup options, unless they are relevant to the issue.
4. Remove any records unless they are relevant to the issue.
5. Delete any objects that do not relate directly to the issue.
6. Remove any references to any "linked" files (files outside of the database, Images, OLE Files, ...etc)
7. Remove any references to any third party Active-x Controls (unless they are relevant to the issue)
8. Remove, obfuscate, encrypt, or otherwise disguise, any sensitive data.
9. Compile the code. (From the VBA code window, click: Debug-->Compile)
10. Run the compact/Repair utility.
11. Remove any Passwords and/or security.
12. If a form is involved in the issue, set the Modal and Popup properties to: No
    (Again, unless these properties are associated with the issue)
13. Post the explicit steps to replicate the issue.
14. Test the database before posting.

In other words, ...post a database that we can easily open and immediately see and/or troubleshoot the issue.
And if applicable, also include a clear graphical representation of the *Exact* results you are expecting, based on the sample data.

JeffCoachman
0
 
LVL 1

Author Comment

by:gordonwwaugh
ID: 37795793
Sorry for the delay. I will create the debugging database requested in the next couple of days.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Accepted Solution

by:
gordonwwaugh earned 0 total points
ID: 37938189
Okay. I have an important correction to my description. Image controls do not have shrink property or a grow property. So, Access is not doing anything unexpected. The VBA code is changing the size of the graphic correctly.

I figured out how to do this. I added some VBA code that moves down the objects below the graphic. In my situation, I have only one object below the graphic: me.txtBanner. Here is the modified code.

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

    Const clngTwipsPerInch As Long = 1440
    Const clngMaxImageWidth As Long = 9360 'in twips, 9360 twips = 6.5 inches
    Const clngMaxImageHeight As Long = 9360 'in twips, 9360 twips = 6.5 inches
    Const clngPadding As Long = 288 'in twips, 288 twips = 0.2 inches
   
    Dim lngImageWidth As Long 'in twips
    Dim lngImageHeight As Long 'in twips
    Dim dblImageRatio As Double
    Dim lngDownwardAdjustment As Double 'in twips

    lngImageWidth = clngTwipsPerInch * Me.txtStemImageWidth
    lngImageHeight = clngTwipsPerInch * Me.txtStemImageHeight

    'If the image is too wide for the page, then shrink it to fit.
    If lngImageWidth > clngMaxImageWidth Then
        dblImageRatio = clngMaxImageWidth / lngImageWidth
        lngImageWidth = dblImageRatio * lngImageWidth
        lngImageHeight = dblImageRatio * lngImageHeight
    End If

    'If the image (even after shrinking for width) is too long, then shrink to fit.
    If lngImageHeight > clngMaxImageHeight Then
        dblImageRatio = clngMaxImageHeight / lngImageHeight
        lngImageWidth = dblImageRatio * lngImageWidth
        lngImageHeight = dblImageRatio * lngImageHeight
    End If

    Me.imgStemGraphic.Width = lngImageWidth
    Me.imgStemGraphic.Height = lngImageHeight

    Me.imgStemGraphic.Picture = Me.txtItemFilename
   
    Me.txtBanner.Top = Me.imgStemGraphic.Height + Me.imgStemGraphic.Top + clngPadding
   

End Sub
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37938642
OK, great.

AFAICT,  you can accept your own post as the solution...

;-)

Jeff
0
 
LVL 1

Author Closing Comment

by:gordonwwaugh
ID: 37960003
No solutions were offered. I figured out the solution myself.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question