Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run-time error 6 overflow

Status
Not open for further replies.

ski2sun

Technical User
Sep 12, 2001
31
US
Please help. I am trying to figure out why in the crazy world I am getting this. Please can someone tell me in simple terms if this is related to some file or table physical size limitation, or a change in the integer/field definitions of the text file I am trying to import. It had been working fine for quite some time and now this....I import a text file, then when I hit the cmd4 button, this appears....Please in the name of Access, help me....thanks so much..Please if you could explain simply, and perhaps modify below what you think might be the fix..thank you,


>Private Sub cmd4_Click()
> Dim dbs As Database
> Dim int1, int2 As Integer
> Dim rst1 As Recordset
> Dim str1 As String
>
> Set dbs = CurrentDb
> Set rst1 = dbs.OpenRecordset("Consign")
>
> rst1.MoveFirst
>
> int1 = 5
>
> Do While Not rst1.EOF
> If Mid(rst1!ConsignAdd1, 5, 1) Like "[a-zA-Z]" Then
> rst1.Edit
> rst1!ConsignAdd1 = "Attn: " & Mid(rst1!ConsignAdd1, 6,
>Len(rst1!ConsignAdd1))
> rst1.Update
> Else
> Do While Not (str1) Like "[a-zA-Z]"
> str1 = Mid(rst1!ConsignAdd1, int1, 1)
> int2 = int1
> int1 = int1 + 1
> Loop
> rst1.Edit
> rst1!ConsignAdd1 = "Attn: " & Mid(rst1!ConsignAdd1, int2,
>Len(rst1!ConsignAdd1))
> rst1.Update
> str1 = ""
> int1 = 5
> int2 = 0
> End If
> rst1.MoveNext
> Loop
>
>
>End Sub
 
A runtime error 6 is always an overflow problem. Overflow only happens when a typed variable, like Integer, can not hold the results of your computation. What happens most often is that the integer value is being used as a counter. A 16 bit integer can hold a value up to 16 to the 2 power of something a little over 32,000. So you see the integer is somewhat limited in the numbers it can store. Changing an integer value to a long value will solve this in 999 out of 1000 cases IF the code is properly constructed.

Dim intCtr As Integer
LoopStart
intCtr = IntCtr + 1
LoopEnd


Change the dimension statement to:
Dim lngCtr As Long

Steve King
Growth follows a healthy professional curiosity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top