[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

resize a picture to fit into an Acccess 2000 report

Posted on 2004-11-04
5
Medium Priority
?
360 Views
Last Modified: 2008-02-01
I'm writing a program where the user has the option to select a picture from their computer and it will be added to their report.  The problem is that the size image that the user selects may be a different size than the Image Control on the Report (approx. 6" x 6").  I'm using Access 2000 / VBA

I am trying to:
1. Determine if the user selected a file that was in a valid file format (.jpg .bmp)
2. Determine the size of the image that the user selected.
3. If the picture that the user selected is too BIG for the Image Control on the Report, then resize the picture to fit into the Image Control
4. If the picture that the user selected is too SMALL for the Image Control on the Report, then don't do anything (I don't want to stretch smaller images).

Sorry for the multi-part question... I couldn't think of any other way to ask it.

Thanks!
Mike
0
Comment
Question by:cdmac2
  • 4
5 Comments
 
LVL 26

Expert Comment

by:Alan Warren
ID: 12502285
Hi Mike,

Think you can put something like this in the OnFormat event of the detail section.
Ensure the default size mode is Clip so you get an accurate image width for the comparison to the image controls width



Dim strPath As String

strPath = "C:\Documents and Settings\Alan\My Documents\Alan2004-001.jpg"
Me.Image0.SizeMode = acOLESizeClip
Me.Image0.Picture = strPath

If Me.Image0.ImageWidth > Me.Image0.Width Then
  Me.Image0.SizeMode = acOLESizeZoom
Else
  Me.Image0.SizeMode = acOLESizeClip
End If
 
 

Take Care...


Alan



0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 2000 total points
ID: 12502464
Hi Mike,

yes that works in the Detail_Format event.

If you have  a table that stores paths to the pics, I had a field called PicsPath.
Then created a report sourced on my table and added the following code to the Detail_Format event

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  Me.Image0.SizeMode = acOLESizeClip
  Me.Image0.Picture = Me.PicPath
 
  If Me.Image0.ImageWidth > Me.Image0.Width Then
    Me.Image0.SizeMode = acOLESizeZoom
  Else
    Me.Image0.SizeMode = acOLESizeClip
  End If

End Sub


Alan
0
 
LVL 1

Author Comment

by:cdmac2
ID: 12503270
Beautiful, works great, Thank You Alan!

My only follow up is, how do I make sure that the user has selected a valid picture file?  

Thanks,
Mike
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 12503894
Hi Mike,

see how this fits your requirements...

Option Explicit

' Reference: Microsoft Scripting Runtime
' Module scope variables
Dim mobjFso As Scripting.FileSystemObject
Dim mobjFile As Scripting.File
Dim mstrPath As String



Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  If Me.PicPath = "" Then: Exit Sub
  Set mobjFso = New Scripting.FileSystemObject
  mstrPath = Me.PicPath

  If mobjFso.FileExists(mstrPath) Then
    Set mobjFile = mobjFso.GetFile(mstrPath)
    With mobjFile
      ' Done it for three image types, add others as you see fit.
      If .Type = "JPEG Image" _
      Or .Type = "Bitmap Image" _
      Or .Type = "GIF Image" Then
        Me.Image0.SizeMode = acOLESizeClip
        Me.Image0.Picture = Me.PicPath
       
        If Me.Image0.ImageWidth > Me.Image0.Width Then
          Me.Image0.SizeMode = acOLESizeZoom
        Else
          Me.Image0.SizeMode = acOLESizeClip
        End If
      End If
    End With
    Set mobjFile = Nothing
  End If

End Sub

Private Sub Report_Close()
  Set mobjFso = Nothing
End Sub




take care...



Alan
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 12511434
Thanks Mike :)
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

872 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