Consulting

Results 1 to 6 of 6

Thread: Solved: Overflow Error #6

  1. #1

    Red face Solved: Overflow Error #6

    I am trying to add several data fields from SQL and input it into Excel.

    I ran this command inside the SQL loop to get the total.

    [VBA]

    Dim NRC_Total As Integer

    Begin Loop

    ' SQL Code to grab a field

    NRC_Total = NRC_Total + Current_SQL_Field

    Loop
    [/VBA]

    About 30 rows in, it popped that OVERFLOW error. Any suggestions?

    Thanks!
    Kaela

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Maybe too many characters, how big is the string?

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Dim as Long not Integer.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    It appears there is no exit from the loop. Try something like
    [VBA]Do

    ' SQL Code to grab a field
    If Current_SQL_Field = "" Then Exit Do
    NRC_Total = NRC_Total + Current_SQL_Field

    Loop
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Kaela,

    Is the value of NRC_Total going over 32,767? That's the max an integer can hold. You may want to try changing the data type to Long to go further.

    Also, I assume that you do have more code in the loop? (Such as a way to exit it?)

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    I can't get over how fast you all reply! You all are the BEST!

    Dim NRC_Total As Long

    Yay! Worked perfect!

    Sorry MD, I was just trying to summarize what I did. The loop works, I'm just too lazy to type it out. Next time I will.

    - Kaela

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •