Change color of button based on query

  • Thread starter Thread starter Frank via AccessMonster.com
  • Start date Start date
F

Frank via AccessMonster.com

I have a form that list records from the data entry table. on this form is
an alert button. on open of the form i need the alert button to change to
the color red if the query returns any records, even one record.

The problem that I am having is that the query is not a part of the form that
list the records. The button tells the user there are alerts waiting so they
can go to the alerts table. It should only turn red if the qryalerts records
any records.

How would i code this on the open of the form to check the qryalerts and if
it returns any records, turn the button red?

Thanks,
Frank
 
I have a form that list records from the data entry table. on this form is
an alert button. on open of the form i need the alert button to change to
the color red if the query returns any records, even one record.

The problem that I am having is that the query is not a part of the form that
list the records. The button tells the user there are alerts waiting so they
can go to the alerts table. It should only turn red if the qryalerts records
any records.

How would i code this on the open of the form to check the qryalerts and if
it returns any records, turn the button red?

Thanks,
Frank

' Command buttons don't allow a change in background color. I suggest
either using a label, or creating a graphic for the command button.

If DCOUNT("fldAlert","tblAlerts","")>0 then
lblButton.Backcolor=vbRed
else
lblButton.Backcolor=vbWhite

Endif
 
I have a form that list records from the data entry table. on this form is
an alert button. on open of the form i need the alert button to change to
the color red if the query returns any records, even one record.

The problem that I am having is that the query is not a part of the form that
list the records. The button tells the user there are alerts waiting so they
can go to the alerts table. It should only turn red if the qryalerts records
any records.

How would i code this on the open of the form to check the qryalerts and if
it returns any records, turn the button red?

Thanks,
Frank

Turn the button red? You can easily change a command button's
Forecolor, but not it's backcolor.

Code the Form's Load event:

If DCount("*","qryAlerts") > 0 Then
Me![CommandName].ForeColor = vbRed
Else
Me![CommandName].ForeColor = vbBlack
End If
 
You cannot change the color of a command button. You could put a graphic on
top of it, but you can just as easily change the font color and font weight
programmatically.
You can use the DCount function with your query to see if it is returning
any rows. Here is an example you would put in the form's Load event.
If DCount("*","qryalerts") > 0 Then
With Me.cmdAlert
.Forecolor = vbRed
.FontWeight = 700
End With
End If
 
I changed it to a label and used:

Private Sub Form_Load()

If DCount("*", "qryAlerts") > 0 Then
Me.lblAlert.BackColor = "255" 'grey
Else
Me.lblAlert.BackColor = "8421504" 'red
End If
End Sub

It Works!!!!!

Thanks,
Frank
I have a form that list records from the data entry table. on this form is
an alert button. on open of the form i need the alert button to change to
[quoted text clipped - 10 lines]
Thanks,
Frank

Turn the button red? You can easily change a command button's
Forecolor, but not it's backcolor.

Code the Form's Load event:

If DCount("*","qryAlerts") > 0 Then
Me![CommandName].ForeColor = vbRed
Else
Me![CommandName].ForeColor = vbBlack
End If
 
See www.lebans.com for some handy stuff regarding button colors --- if
you're still interested. Bob

Frank via AccessMonster.com said:
I changed it to a label and used:

Private Sub Form_Load()

If DCount("*", "qryAlerts") > 0 Then
Me.lblAlert.BackColor = "255" 'grey
Else
Me.lblAlert.BackColor = "8421504" 'red
End If
End Sub

It Works!!!!!

Thanks,
Frank
I have a form that list records from the data entry table. on this form
is
an alert button. on open of the form i need the alert button to change
to
[quoted text clipped - 10 lines]
Thanks,
Frank

Turn the button red? You can easily change a command button's
Forecolor, but not it's backcolor.

Code the Form's Load event:

If DCount("*","qryAlerts") > 0 Then
Me![CommandName].ForeColor = vbRed
Else
Me![CommandName].ForeColor = vbBlack
End If
 
Back
Top