How can I disable a Print Command button?

ProjMan

New member
Local time
Today, 11:24
Joined
Feb 6, 2012
Messages
3
I have created a command button on my form which allows the printing of the current record in this case an Inspection record. It all words fine however I also have code in the form such that if the item has passed inspection, the fields following it are no longer enabled. Which again works. The code for this is:
Private Sub Passed_Click()
If Passed.Value = False Then
Fault_Code.Enabled = True
Comments.Enabled = True
Else: Fault_Code.Enabled = False
Comments.Enabled = False
Similarly if this item has passed inspection I want to be able to disable the command button which allows printing named "PRTReport" but when I enter code such me.PRTReport.Enabled=False or simply PRTReport.Enabled=False. The code fails when the form reaches the passed check box.

Has anyone any ideas please where i am going wrong.

Many Thanks

Clive
 
What is the failure you are getting? If I read your description correctly, then Passed is a command button? Command buttons don't have a value property, which may be the reason for the failure you have.
The thing I notice about your code block is the 'Else:' which seems wrong in context. Try removig the colon and putting the following statement on the next line. I assume the 'End If' follows the last line of your extract?
 
A couple of things.

1. Don't use the Click event of the checkbox, use the After Update event.

2. You will need to call the same code in the form's On Current event so that when you move to a record which has this criteria you will not have things enabled.

3. So create a Procedure within the form's module which you can call from both the After Update event of the checkbox and the On Current event of the form.

Code:
Private Function SetPassed()
   Me.FaultCode.Enabled = Not Me.Passed
   Me.Comments.Enabled = Not Me.Passed
End Function

Then you just call the function SetPassed from the after update event of the checkbox and the form's On Current.

And I rewrote your code to be shorter and not require the If Then Else statement. It sets the enabled property to the opposite of the checkbox value. So, if the checkbox is true then the enabled is false. If the checkbox is false, then the enabled is true.

Also, to call it from the events it would look like:
Code:
Private Sub Passed_AfterUpdate()
   SetPassed
End Sub
 
 
Private Sub Form_Current()
   SetPassed
End Sub
 
Hi, thanks for your reply, the "Passed" field is a yes/no tick field, therefore if the value is false, i.e the item has failed then both the fault code (drop down list) and Comment field ( Memo) are available for completion and therefore I want the command button to be able to be pressed and print a copy of the inspection report. If the item has passed - value is true then both the faultcode and comments field are not enabled and I want the command button not to either be visible or enabled so they cannot print a report.

The error I got as I was trying something else was Object Required, I had just tried to change the code to CMDBUtton.Print_Report.Enabled=False

Hope this helps

Clive
 
Sorry, I thought Passed was a checkbox and not a command button. But now that I re-read the posts and also NickHa's post I'm not so sure.
 
Hi, thanks for your reply, the "Passed" field is a yes/no tick field, therefore if the value is false, i.e the item has failed then both the fault code (drop down list) and Comment field ( Memo) are available for completion and therefore I want the command button to be able to be pressed and print a copy of the inspection report. If the item has passed - value is true then both the faultcode and comments field are not enabled and I want the command button not to either be visible or enabled so they cannot print a report.

The error I got as I was trying something else was Object Required, I had just tried to change the code to CMDBUtton.Print_Report.Enabled=False

Hope this helps

Clive
What I wrote should work then but to reference the command button you need to use the name of it like this:

Me.Print_Report.Enabled = Not Me.Passed

(that is, if the command button name is exactly Print_Report with the underscore)
 
Bob,

Sorry to be confusing, You are right the Passed field is a check box (value Yes/No - ticked or not ticked). This then currently blanks and skips the fields Fault Code and Comments, if the Passed Check Box is Ticked. I then want the command Button responsible for the printing of the record to be disabled (again if the passed field is ticked). There is no point printing a failure report when something has passed.

Thanks for the other code and for your help

Clive
 

Users who are viewing this thread

Back
Top Bottom