×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Run Time Error 6 Overflow

Run Time Error 6 Overflow

Run Time Error 6 Overflow

(OP)
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?

CODE --> VBA

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 

RE: Run Time Error 6 Overflow

I would try change some integers to Long. The maximum value for an integer is 32767. Have you determined the values by setting a breakpoint or using debug.print?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Run Time Error 6 Overflow

The problem is that, for whatever reason, both picWdt and picHgt are zero

RE: Run Time Error 6 Overflow

Good catch Strongm. I typically check a divisor for 0 before performing a division.

The size and resolution of current monitors can also cause errors if you have code that uses a variable to set the form or control width larger than what an integer can support.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Run Time Error 6 Overflow

For the specific overflow shown here (where pic seems to be equal to -1.#IND) both numerator and denominator have to be 0

The reason I said "for some reason" was to try and encourage the OP to investigate - but I'm having a quiet day, so ... this would typically happen in this specific example if thhere was no picture currently assigned to the Image control (and thus both ImageHeight and ImageWidth would be 0)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close