Enable/Disable button

eugz

Registered User.
Local time
Today, 07:19
Joined
Aug 31, 2004
Messages
128
Hi All.
I created condition for form when fields are empty the button is disable. But it works in case with one field. When user enter data in one of the field button become enable. I would like that button become enable only when all fields was filled up. And button is disable when user open form or new record and value of the fields is NULL or empty. Where is my problem?

Code:
Private Sub txtField1_BeforeUpdate(Cancel As Integer)
    If (IsNull(Me.txtField1.Value) Or (Me.Field1.Value = "")) Then
        Me.cmdCreate.Enabled = False
    Else
        Me.cmdCreate.Enabled = True
    End If

End Sub

Private Sub Field2_BeforeUpdate(Cancel As Integer)
    If (IsNull(Me.Field2.Value) Or (Me.Field2.Value = "")) Then
        Me.cmdCreate.Enabled = False
    Else
        Me.cmdCreate.Enabled = True
    End If

End Sub

Private Sub Field3_BeforeUpdate(Cancel As Integer)
    If (IsNull(Me.Field3.Value) Or (Me.Field3.Value = "")) Then
        Me.cmdCreate.Enabled = False
    Else
        Me.cmdCreate.Enabled = True
    End If

End Sub
Thanks.
 
Your problem is that you are enabling whenever a single field gets updated. You could create a sub, or function, that is called whenever a field gets updated and it could check to see if all fields are filled out.

Normally, you could use the form's BeforeUpdate event to validate before the record is saved, but it would seem that you want to have a command button be available after all fields are filled out.
 
As stated by boblarson, one of the approaches would be to create a sub which is called whenever needed.
Code:
Private Sub ToggleCommandButton()

    Me!cmdCreate.Enabled = _
        (Len(Me.txtField1.Value & vbNullstring) And _
        Len(Me.txtField2.Value & vbNullstring) And _
        Len(Me.txtField3.Value & vbNullstring))

End Sub
then call it from both the on current event of the form, and the after update event of each of the text controls.
 

Users who are viewing this thread

Back
Top Bottom