Enable Command Button After Update

gnarpeggio

Registered User.
Local time
Today, 02:50
Joined
Jun 22, 2010
Messages
74
Hello,

I'm trying to write a simple If statement for my form that enables a command button only when a value is entered into the text field.

This is my first guess:

Sub Barcode_AfterUpdate

If Me.Barcode = "" Then
Me.cmdPrintNew.Enabled = False
Else
Me.cmdPrintNew.Enabled = True
Me.Barcode = UCASE (Me.Barcode)

End If

End Sub

Note: The UCASE statement is to ensure the value becomes capitalized every time a value is entered.

Should I set the .Enabled property to No in the Form properties prior to this? Any help would be appreciated!

Thanks!
Matt
 
Instead of the After Update for setting the UCASE use the before update event of that control.

The rest can work simply by saying:

Code:
Me.cmdPrintNew.Enabled =  Len(Me.Barcode & vbNullString) > 0

You may need to add that to the form's On Current event too.
 
Thanks Bob,

In closing, should the following statement

Me.cmdPrintNew.Enabled = Len(Me.Barcode & vbNullString) > 0

be placed in both the On Current and the After Update, or the Before Update event?

Thanks again,

Matt
 
Thanks Bob,

In closing, should the following statement

Me.cmdPrintNew.Enabled = Len(Me.Barcode & vbNullString) > 0

be placed in both the On Current and the After Update, or the Before Update event?

Thanks again,

Matt

I would put in the After Update of the control and the On Current of the form. And add parens I think I forgot:

Me.cmdPrintNew.Enabled = (Len(Me.Barcode & vbNullString) > 0)
 

Users who are viewing this thread

Back
Top Bottom