Disabling and Enabling a button. PLEASE HELP, VERY IMPORTANT

alireza1989@hot

Registered User.
Local time
Today, 12:41
Joined
Feb 26, 2007
Messages
23
Hi, I have a form called Product Details Display Form, which is for Product Details Display table. This form contains a button "Done" which saves everything into the table, or in other words, bounds the unbounded textboxes to the table. Basically, I want this button to be disabled at the begining, when the form loads, and when the user enters ALL the fields, it becomes enabled. Here is the code I have at the moment:
Code:
Private Sub Form_DataChange(ByVal Reason As Long)
If Me.Product_Brand = Null Or Me.Product_Code = Null Or Me.Product_Name = Null Or Me.List34 = Null Or Me.Price = Null Or Me.Details = Null Or Me.Discount = Null Or Me.Combo0 = Null Or Me.Combo2 = Null Then
Me.Command36.Enabled = False
Else
Me.Command36.Enabled = True
End If
End Sub

I also have Me.Command36.Enabled = False in the Form-Load. I dont really know if it has to be in Private Sub Form_DataChange or not.

Please help me ASAP

Thanx in Advance
 
Nothing is equal to Null. Use IsNull() to test for Null:

If IsNull(Me.Whatever)...
 
Yes, that works perfectly. But the button enabling doesn't work. Can you please help me with that
 
You cannot do this simply, but...

Make a subroutine or function. (I vote for a Boolean Function, but hey, it's your project.)

Call this function from every OnChange routine for every control that relates to your decision to enable the button. From the OnChange routine, it might be so simple as

Private Sub xxxxx_Change()

button.Enabled = myfunction()

Exit Sub

The idea is that this function "knows" every control on your form (or steps through the collection of controls to determine the ones that can be updated) and when all controls are acceptable, it returns TRUE (YES). Otherwise it returns FALSE (NO).

The Form_Current event is as good a place as any to put the disabling code, I wouldn't change that choice at all.
 
That looks good, but what do you actually write in the function (or subroutine)
 

Users who are viewing this thread

Back
Top Bottom