Kaw4Life
Kaw4Life

Reputation: 209

VBA Overflow Error 6 Not really

=Count([qty_rec])/Count([sub]) is the control source for a text box. Format for the control is 'percentage'. I have also tried 'standard', fixed and leaving it blank. I suspect the evaluation is comparing apples to oranges.

Private Sub Form_Current()
If Me.txt_percent_received = 0.5 Then
    Me.cbtn_shortage.Visible = False
Else
End If
End Sub

I put breakpoint at If and goto to immediate and type ?Me.txt_percent_received

It says 0.5

Why does system think this number is too big?

and why does it work if I step thru the code?

Updated

Dim intTemp As Integer
intTemp = Me.txt_percent_received
If intTemp = 0.5 Then
Me.cbtn_shortage.Visible = False
Else
End If

Now the error is on intTemp = Me.txt_percent_received

qty_rec and sub are for totaling populated fields.

Upvotes: 0

Views: 311

Answers (1)

Andre
Andre

Reputation: 27634

I have reproduced the effect, and I think what happens here is:

Calculated controls are evaluated after the form has finished loading. If you remove the event code, and open the form, you will notice that the value of txt_percent_received is displayed with a slight delay.
You may even notice that at first it displays #Number!, and then calculates the value.

But the form events happen before that, so what you get is a division of 0/0, and this gets runtime error 6 "Overflow".

1/0 would get error 11 "Division by zero".

You need a different way either to calculate txt_percent_received, or to implement your cbtn_shortage logic.

Upvotes: 1

Related Questions