Thread: VBA Error
View Single Post
  #4   Report Post  
George Nicholson
 
Posts: n/a
Default

I avoid using the Text property whenever possible. I can't find it in Excel
VB Help, but I remember some sort of restriction that the Text property of a
TextBox is only accessible when that control has the focus. Your code uses
the Text property of 3 controls. Obviously, only 1 control can have the
focus at any given time. It could be I'm confusing the TextBoxes of
UserForms, Access and VB6, all of which are slightly different animals, but
I still would eliminate it as the potential problem first.

Setting Text also sets Value. Value is the default property of TextBoxes.
Why not just use that?

Try changing
Me.txtVel2.Value = (Val(Trim(txtDis2.Text))) / (Val(Trim(txtHrs2.Text)))
to
Me.txtVel2 = (Val(Trim(txtDis2))) / (Val(Trim(txtHrs2)))
and see if you get better results.

HTH,
--
George Nicholson

Remove 'Junk' from return address.


"mully" wrote in message
...
Hi

On a UserForm everything works OK all the boxes fill with the correct
information -- however on hitting enter the following error message
appears.

Division By Zero

in the VBA the bottom line of the following code is highlighted

Private Sub txtHrsTime_Change()
Me.txtHrs2.Value = (Val(Trim(txtHrsTime.Text))) * 60
Me.txtVel2.Value = (Val(Trim(txtDis2.Text))) / (Val(Trim(txtHrs2.Text)))
End Sub

On viewing the sheet everything has been entered in the correct Cells --
this bug is really bugging me.

Also how do you restrict the numbers after the decimal point in a Text
Box.

Any help much appreciated

Cheers ---- Mully