Form Text Box Control Events

PNGBill

Win10 Office Pro 2016
Local time
Today, 20:04
Joined
Jul 15, 2008
Messages
2,271
Hi forum, Access 2010 accdb

I have a form with an unbound Text Box Control.

The Control Source is defined by the Form On Open Event.
One option is for a string (function) to populate the Text Box Control and the other is for a Value to be placed in the control.

Both options result in automatic population of the control with a Currency value.

I would like a Command Button control to be Enabled - True or False depending on the value. as per the code below.

Code:
Dim LateFee As Currency
    LateFee = Me.txtLateFeesToBeCharged
    
    If LateFee = 0 Then
        Me.CmdChargeLateFee.Enabled = True
    End If

I have tried AfterUpdate and Dirty without success :confused:

Any other options or methods to get this to react ??

Appreciate any advice :)
 
Remove the Me. as Me refers to the control that is used for data. for buttons etc use the name without the Me.

Assuming your text field is called txtLateFeesToBeCharged then you will need code similar to this
Code:
sub txtLateFeesToBeCharged_Afterupdate()
If Me.txtLateFeesToBeCharged=0 then
CmdChargeLateFee.Enabled = True
else
CmdChargeLateFee.Enabled = false
End If
 
end sub
You could replace Me.txtLateFeesToBeCharged with
Dim LateFee As Currency
LateFee = Me.txtLateFeesToBeCharged

If LateFee = 0 Then
etc.
 
I tried this
Code:
Private Sub txtLateFeesToBeCharged_AfterUpdate()
    
    Dim LateFee As Currency
    LateFee = Me.txtLateFeesToBeCharged
    
    If LateFee <> 0 Then
        CmdChargeLateFee.Enabled = True
    Else
        CmdChargeLateFee.Enabled = False
    End If
    
End Sub
But it isn't Kicking In.

I was playing earlier and this works
Code:
Private Sub Form_Timer()
    Dim LateFee As Currency
   On Error GoTo Form_Timer_Error
    LateFee = Nz(Me.txtLateFeesToBeCharged, 0)
    If LateFee <> 0 Then
        CmdChargeLateFee.Enabled = True
    End If
End Sub

Timer is set to 1000 but it doesn't appear to make a difference how long it takes for the function to load a value in the control but when it does, the command button is enabled.

Why is time working and after update doesn't ?

It appears timer waites for the function to complete ??
 
Use this code

Sub Form_Open(Cancel As Integer)
Me!txtLateFeesToBeCharged = 0
check_late_fees
End Sub

Sub txtLateFeesToBeCharged_AfterUpdate()
check_late_fees
End Sub

Sub check_late_fees()
If Me!txtLateFeesToBeCharged = 0 Then
CmdChargeLateFee.Enabled = True
Else
CmdChargeLateFee.Enabled = False
End If
End Sub


The Open event triggers when the form opens and assigns a value of 0 to the text box, then the sub procedure check_late_fees is called and enables the button depending on the value of the text box as 0 is the value then the button is enabled. If 12 is entered in the text box then the button is not enabled. The sub procedure check_late_fees saves the duplication of coding for the textbox value.
 
Actually you should put the IF...ELSE code (provided by Poppa Smurf) in the Current event of the form and the After Update event of the control.
 

Users who are viewing this thread

Back
Top Bottom