Home>


The records in the table are displayed in the form form

<>
I want to display only records that match certain conditions in a form with a different background color

Error message

If there is a record with "A" in [Field name 1],

I want to change the background color of the form where the record is displayed.

When I wrote the following code as a test, it was not reflected.

I wanted to change the code, but I'm not sure where to change it.

If i have a good method, please let me know.

Private Sub Form_Load ()
 Dim SQL1 As String
 SQL1 = ""
 SQL1 = "SELECT [table name]. [Primary key field]"
 SQL1 = SQL1&", [table name]. [Field name 1]"
 SQL1 = SQL1&", [table name]. [Field name 2];"
 Forms! [Form name for display] .RecordSource = SQL1
 Forms! [Form name for display] .Form.Requery
 If [Form name for display]. [Control name 1] = "A" Then
  [Form name for display] .Details.BackColor = RGB (204, 255, 204) 'Light green
 End If
End Sub
  • Answer # 1

    Because the "Background color" property is not included in each record, even if it is changed in VBA, it is reflected in all records. It is impossible to change the background color for each record.

    Use conditional formatting to change the format for each record.
    Only text boxes have "conditional formatting", so place a text box of the same size as the section on the back and set the background color in the conditional formatting.


      

    If there is a record with "A" in [field name 1],
      I want to change the background color of the form where the record is displayed.

    Example of conditional formatting

Related articles