Text Boxes and Numbers

stoka

Getting Better
Local time
Today, 11:40
Joined
Jan 22, 2007
Messages
23
My table has the field defined as number, and in form i input a value. I have an OnChange subroutine that tries to look at this field, and if the value > 0 to turn on a check box. however it does not work.
'if family leave hours are present turn on chkFamLeaveFlag
Private Sub txtFamLeaveHrs_Change()
Dim dblValue As Double
dblValue = 0
dblValue = Me.txtFamLeaveHrs.Value

If dblValue > 0 Then
Me.chkFamLeave = True
Me.txtTestValue = dblValue
End If
Me.lblTestInSub.Visible = True
End Sub
is there something about the table def being numeric, and the text box always being character and having to convert the value of the text box to numbers before doing a compare...i don't get an error this way so not sure why the test result of dblValue is always zero even in the text box shows an input of 5 for example.
thanks
 
First, the OnChange event is going to recheck the field after each character is entered into the TextBox. For example, if I enter "123" into the TextBox, the code will run for "1", then "12", and then "123". You want to use the BeforeUpdate event instead.

After that, assuming you're linking your form to a table, then you want to requery and then refresh the form. Something like this is cleaner:

Code:
'if family leave hours are present turn on chkFamLeaveFlag
Private Sub txtFamLeaveHrs_BeforeUpdate(Cancel As Boolean)

    If Me.txtFamLeaveHrs.Value > 0 Then
        Me.chkFamLeave = True
        Me.txtTestValue = Me.txtFamLeaveHrs.Value
    End If

    Me.lblTestInSub.Visible = True
    Me.Requery
    Me.Refresh

End Sub
 
Is the textbox name really txtTestValue or have you forgotten the period between txtTest and Value, and should the line

Code:
Me.txtTestValue = dblValue

actually be

Code:
Me.txtTest[B].[/B]Value = dblValue
:confused:
 
The reason your code fails is because during the Change event, the .Value property doesn't have the new value. You'd want to use the .Text property instead.
 

Users who are viewing this thread

Back
Top Bottom