runtime 6, overflow

pablavo

Registered User.
Local time
Today, 13:34
Joined
Jun 28, 2007
Messages
189
Wonder if someone can help me with this problem.

I've got a form with text boxes to create a percentage out of records that have a numeric field.
there are text boxes that allow the user to select a currency band i.e £0.00-£50,000.00 etc and then hit a command button which will show the percentage of records that within this band.

This is the code:

If Not IsNull(Me.txtMin) And Not IsNull(Me.txtMax) Then
Me.txtPerc = (DCount("*", "qryPercentage") / Me.txtTotal) * 100 & "%"
End If


on top of the two text boxes I have another that the user can add the year the wish to use as criteria to search apon.

If I select higher than say, the year 2010 I get a 'runtime 6 overflow'

Is there anything I can do to prevent this?

Thanks for anyhelp
 
It sounds like the numeric value of the "year" textbox is playing into this code.

Is the code you posted the only code you have that relates to this issue?

Where does the year come from? Are the years different fields in one table?
 
Souds like you have declared a variable as an integer or another numeric datatype and the value you are trying to assign is outside the range of that datatype. Post the part of your code where your declare your variables.
 
Check that you're not trying to divide by zero to get your percentage.

e.g.

Me.txtPerc = (DCount("*", "qryPercentage") / Me.txtTotal) * 100 & "%"

This will create an overflow error if Me.txtTotal = 0.

It's something worth checking at least.

Pete
 
Thanks for the reply folks.

The code I've shown is the only code, there is no Variables. I'm not really sure if and what was needed in regards to variables.

PetehillJnr, I think it might be something to do with a 0 but not with the txtTotal.
The query the code refers to, qryPercentage referecnes the Currency amount within the two text boxes which is
Between [Forms]![frmPercentage]![txtMin] And [Forms]![frmPercentage]![txtMax]


The year text box "txtFinanceYear" is referencing the a a year field with the expression: [Forms]![frmPercentage]![txtFinanceYear]

I think my problem might be the txtFinancialYear. after 2010 there are no more years so this is blank. I'm hoping this is why I'm getting the overflow.

Do you think this might be the case?

Technically this should be on a different thread but since it's sort of related... The Percentage is giving me the decimals and I'm not really sure how to avoid this. Perhaps I need to declare one of the calculations within the code as a Integer?

Thanks.
 
I think my problem might be the txtFinancialYear. after 2010 there are no more years so this is blank. I'm hoping this is why I'm getting the overflow.
Isn't the cutoff for years 2029 in Access? After that number, the program doesn't read the value as a year anymore, because it is not stored. Isn't that right?
 
oops, sorry, I didn't explain that one at all.
what I meant was, in the database the record with the highest year is 2009, anything after this will be added in time when the records are created. That's why I'm getting the 'Overflow' I'm sure of it now. So, I've just handled the error.

I'm still stuck on how to stop access from showing the decimals. Does anyone know how to stop this.
I thought turning the datatype into an integer would do it but I don't really know where I'd do this with a text box expression; I don't think any user is interested in seeing '58.1836734693878%'

thanks
 
Can't you just set the decimal places in the control's properties? Or, how about the format() function in VB? Surely you can do this.
 
I've tried to set Decimal Places to '0' alreay, that doesn't work. I'm not as experienced as a lot of members here and I always make sure I do as much research as I can. I've looked for articles on how to deal with the Format() in regards to striping the Decimals and can't find anything.

I'll keep looking. Perhaps if you know of a site that could help I'd be grateful.
Thanks
 
I used the Int() function to strip the Fractions. Found it in the book 'Data Analysis' and had help with the syntax.

Me.txtPerc = Int((DCount("*", "qryPercentage") / Me.txtTotal) * 100) & "%"


Thanks again for taking the time to help.
 
I used the Int() function to strip the Fractions. Found it in the book 'Data Analysis' and had help with the syntax.

Me.txtPerc = Int((DCount("*", "qryPercentage") / Me.txtTotal) * 100) & "%"


Thanks again for taking the time to help.

If that works then good. If your text box was returning '58.1836734693878% then putting "0.00%" into your textbox format should have worked also.
 

Users who are viewing this thread

Back
Top Bottom