Enable a command button

N

Nick T

Hi,
I have a text box on my form and also a command button for which when
clicked, the form is printed.
However, i do not want users to be able to print the form unless data is
entered into the text box. Is there any code i can put in the text box event
which eg: 'AfterUpdate activate 'Print Button' ??

At all other times i want the 'Print Button' to be inactive, so do i need to
set the properties of the print button to 'Enabled - No'??

Any suggestions ? In laymans terms??
Thanks in advance
 
A

adam.vogg

in the form open event, disable it first like:

Private Sub Form_Open(Cancel As Integer)
Me.printbutton.Enabled = False
End Sub



Then in the after update command on your text box,

Private Sub YouTextBox_AfterUpdate()
If Me.YourTextBox.Value <> Null Then
Me.printbutton.Enabled = True
Else
Me.printbutton.Enabled = False
End If


End Sub
 
A

Arvin Meyer [MVP]

You'll need this code in the control (textbox) AfterUpdate event, and also
in the form's Current event. Set the Enabled property of the button to No,
then (aircode):

Sub txtWhatever_AfterUpdate()
If Len(Me.txtWhatever & vbNullString) > 0 Then
Me.cmdPrint.Enabled = True
Else
Me.cmdPrint.Enabled = False
End If
End Sub

obviously you need to substitute your controlnames.
 
N

Nick T

Hi,
Iv done this, however seem to have a problem.

I have the code in place, however when opening the form i get an error
message saying Compile Error: Invalid or unqualified reference.

The .Enabled part of the code is highlighted in the VB code.

Any suggestions? where am i going wrong?
Thanks
 
N

Nick T

Hi,
Still having problems - iv put the code as detailed in the relivant places
and im getting an error - Compile Error: Method or data member not found.

Any suggestions?
Thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top