Sorry, another conditional formatting question

PiedPiper70

Registered User.
Local time
Today, 20:56
Joined
Oct 21, 2012
Messages
115
Access 2003, in a continuous form I have a number of fields and a command button. I would like to hide the button if a condition is met on one of the fields.

Anyone know if this is possible?

Thanks
Dave
 
Perhaps you could use some code the form's OnCurrent event to hide/show the button. If the field can be edited then you would need the same code in the field's AfterUpdate event. Actually, forms don't have fields. They have controls, like text boxes, combo boxes etc that are bound to fields in the forms data source.
 
Perhaps you could use some code the form's OnCurrent event to hide/show the button. If the field can be edited then you would need the same code in the field's AfterUpdate event. Actually, forms don't have fields. They have controls, like text boxes, combo boxes etc that are bound to fields in the forms data source.

You're right of course, I know what I meant, I just used the wrong word.

I don't think your idea would work on a continuous form. Just to be clear each row of my form contains 4 text boxes and a command button. One of the text boxes contains a numerical value. If that value is -999999 then I want to hide the command button on that row, and that row only.

I hope that's a clearer description of what I'm trying to achieve

Thanks
Dave
 
With Continuous View Forms, any formatting you do to a Control on one Record is how the Control appears on all Records. In a lot of cases, depending on exactly what you need to do, you can use Conditional Formatting off of the Ribbon/Menu. But you cannot do everything using CF, and you cannot use CF on all Controls. And sadly, for you, one of the things you cannot do is to control the visibility of a Control, and you cannot use CF on Command Buttons! A double whammy!

I see two possibilities, here:

Leave you Command Button on the Detail Section of the Form, meaning have the button appear on each Record, but change what happens when it is clicked for any given Record. If the Target Field = -999999, pop up a Messagebox telling the user that the button's function is not available for that Record, otherwise let the button function as designed.
Code:
Private Sub CommandButtonName_Click()
 If Me.TargetField = -999999 Then
  MsgBox "This Function Not Available for this Record!"
 Else
  'Code goes here to do whatever the Command Button is supposed to does
 End If
End Sub
Or, move the Command Button to the Header Section of the Form, and use code to conditionally hide/show it.
Code:
Private Sub Form_Current()
 If Me.TargetField = -999999 Then
  CommandButtonName.Visible = False
 Else
  CommandButtonName = True
 End If
End Sub
You'd also need to have this same code in the AfterUpdate event of the Target Field. The Command Button will only be Visible, in the Header, when the Current Record doesn't have -999999 in the TargetField. Clicking it will do so in reference to that Current Record, and it'll look better to have the one button, appearing/disappearing, depending on the Current Record, than to have all buttons on all Records, doing the same thing.

Linq ;0)>
 
Last edited:

Users who are viewing this thread

Back
Top Bottom