resize a picture to fit into an Acccess 2000 report

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
LVL 1
cdmac2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alan WarrenApplications DeveloperCommented:
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
Alan WarrenApplications DeveloperCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cdmac2Author Commented:
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
Alan WarrenApplications DeveloperCommented:
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
Alan WarrenApplications DeveloperCommented:
Thanks Mike :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.