Run Time Error

randolphoralph

Registered User.
Local time
Today, 13:37
Joined
Aug 4, 2008
Messages
101
I am trying to write a function and need some input

The three fields I have are:
TotalPoints
TotalPosPoints
OverallScore

I am trying to take TotalPoints/TotalPosPoints and display the results in the OverallScore Field. I have written the code but I keep getting a "Runtime error '6':
Overflow

Here is the code I have so far

Code:
Private Sub Form_Current()
 
Me.OverallScore = Me.TotalPoints / Me.TotalPosPoints
 
End Sub
http://www.access-programmers.co.uk/forums/showthread.php?p=734735#post734735
 
Current means it keeps refreshing, so why do you have this in the current action? put it in the textbox field instead as a default value
 
I had put this under the current action so that it will update the underlying table on the OverallScore field.

I first tried putting =[TotalPoints]/[TotalPosPoints] into the text box and when I look at the record in the table it shows 100% and the form shows 96%
 
I first tried putting =[TotalPoints]/[TotalPosPoints] into the text box and when I look at the record in the table it shows 100% and the form shows 96%
is your control bound? that might be cause. another might be rounding.

The error #6 might be the cause of data type compliance. Wrong data type for the control?

Like rainman said, you really need to take the calculation off of the current event of the form. Additionally, if the number is supposed to be stored in a field, you cannot assign a value to it using the control source, nor can you with the default value, because it is bound to a table, which already has fields that are assigned default values to themselves. You can't manipulate the default value that is already set by the source (I don't think anyway). Default values on forms work for unbound textboxes only (using the data tab under properties), I think...
 
Yes the field is bound. So I can not assign the value to the control source or the default value since it is bound. Instead of adding this to the Current Event can I add it to something else? Is there a work around? Any suggestions?

Not sure if it helps but all 3 fields are set to Number data type under the Table. The TotalPoints and TotalPosPoints fields calculate whole numbers under the current event. Each of those fields use Case statements to count "Yes", "No" in other fields. The OverallScore field displays percents with no decimals.
 
so you are trying to set the overall score in your table? why is the overallscore textbox bound?
 
Yes I am trying to set the overall score in the table.

I am pretty sure that it is bound...I know this may be a dumb question but how do I tell if it is?

The Overall Score field is specific to each record and would need to change each time I move to a new record.
 
as a general rule of thumb, you should not store calculations in tables, this can be done on the fly, and it really is not neccesary to store the value. you can instead, do it in a query, or even on the form.

You should think about what you need this stored for.

you can tell if its bound by looking at the control source of the textbox's properties.
 
The Overall Score field is specific to each record and would need to change each time I move to a new record.
If that IS the case, assign this as the control source of the UNBOUND text box (it will NOT be part of your table. It will also not be a field in your table, but WILL be displayed on your form as "part" of the record):
Code:
= me!firstTextBox / me!SecondTextBox
It's that simple. It will automatically change values with the records.

you can tell if its bound by looking at the control source of the textbox's properties.
Also Randolph, don't confuse the word "bound" with the phrase "bound to a table". A control is bound many ways, not just to a table. Can be an expression or function as well, as i've specified above in the code line... ;)
 

Users who are viewing this thread

Back
Top Bottom