nikademous
Technical User
I found a module to resize my image frame and I keep getting a Overflow error when it opens and it takes me to:
Any ideas on how to fix?
Any ideas on how to fix?
Code:
Option Compare Database
Option Explicit
'This function will resize and center an image frame based on the
'dimensions of any image.
Public Function fResizeImageFrame(ctl As Control)
Dim fraLeft As Integer
Dim fraTop As Integer
Dim fraHgt As Integer
Dim fraWdt As Integer
Dim picHgt As Integer
Dim picWdt As Integer
Dim pct As Double
Dim fra As Double
Dim pic As Double
'get dimensions of the image frame
fraLeft = ctl.Left
fraTop = ctl.Top
fraHgt = ctl.Height
fraWdt = ctl.Width
'get dimensions of the image in the frame
picHgt = ctl.ImageHeight
picWdt = ctl.ImageWidth
'get a percent value for the frame and image
'which is based on the dimensions of each
fra = fraWdt / fraHgt
pic = picWdt / picHgt
'pics dimensions smaller than entire frame
If fraHgt > picHgt And fraWdt > picWdt Then
'resize frame to fit pic
ctl.Height = picHgt
ctl.Width = picWdt
'center frame
ctl.Left = fraLeft + ((fraWdt - picWdt) / 2)
ctl.Top = fraTop + ((fraHgt - picHgt) / 2)
'pics dimensions taller than frame dimensions
ElseIf pic < fra Then
'determine percentage the pic is being reduced
pct = fraHgt / picHgt
'calculate the new pic width
picWdt = picWdt * pct
'resize frame to fit pic
ctl.Width = fraWdt - (fraWdt - picWdt)
'center frame
ctl.Left = fraLeft + ((fraWdt - picWdt) / 2)
'pics dimensions wider than frame dimensions
ElseIf pic > fra Then
'determine percentage the pic is being reduced
pct = fraWdt / picWdt
'calculate the new pic height
picHgt = picHgt * pct
'resize frame to fit pic
ctl.Height = fraHgt - (fraHgt - picHgt)
'center frame
ctl.Top = fraTop + ((fraHgt - picHgt) / 2)
End If
End Function