Gary
Gary

Reputation: 21

Display Button on Form (Continuous) Depending on record

I have a list of Records that I am Displaying in a continuous form. I am also putting buttons in this form.

IE I have a list of "exams" on the list I have buttons for each exam such as a DELETE Button, EDIT button and so forth. I want to add another button only if the exam has a certain variable set.

Record Set Example

| Key | ExamName    | ExamLocation | ExamDate | ExamComplete |
|-----|-------------|--------------|----------|--------------|
| 1   | Test Exam 1 | TX           | 10/2/19  | Y            |
| 2   | Test Exam 2 | SC           | 10/4/19  | Y            |
| 3   | Test Exam 3 | AL           | 10/29/19 | N            |
| 4   | Text Exam 4 | WA           | 10/22/19 | Y            |

so for each on of the records that have a 'Y' set for ExamComplete, I want to display a button but not for those with a 'N'

I have monkeyed with the "onCurrent" and "onLoad" event with no success.

Example CODE

If me.ExamComplete.Value = "Y" Then
    Me.BtnClickOpen.visable = TRUE
ELSE
    Me.BtnClickOpen.visable = FALSE
END IF 

Any Ideas?

Upvotes: 0

Views: 2393

Answers (2)

ComputerVersteher
ComputerVersteher

Reputation: 2696

Just discoveredDetail_Paintevent can be used for conditional format on Buttons (and other controls withoutFormatConditionsproperty) in a continuous formsDetail-Section. Although you can't set the visible property, you can set the.Transparentproperty. AsButton_Clickevent fires on transparent button too, you have to check in click event wether code should be executed or not.

Private Sub Detail_Paint()
  Me.BtnClickOpen.Transparent = Not Me.ExamComplete.Value = "Y"
End Sub

Private Sub BtnClickOpen_Click()
  If Me.ExamComplete.Value = "Y" Then
    ' button visible(not tranparent), execute button-click code
  Else
    'button transparent, do nothing
  End If
End Sub

Upvotes: 1

June7
June7

Reputation: 21389

Place buttons in form Header section. If ExamComplete is a Yes/No field type, don't put parameter within quote marks. Regardless of field type, a one-liner is possible - for Yes/No, just reference the field.

Me.BtnClickOpen.Visible = Me!ExamComplete

Certainly want code in form Current event but possibly also in ExamComplete checkbox AfterUpdate.

There is only one button so VBA setting property impacts ALL instances of button - each record will display the same. It will work in Detail section but can be distracting and confusing to user with all button instances disappearing/appearing. Alternative is textbox with Conditional Formatting (no VBA) to emulate a button in Detail section. The textbox will always be visible (unless rule changes background color to match form so it blends in) and dynamically enabled/disabled individually per record.

Upvotes: 1

Related Questions