Change command button color if underlying form has data?

WinDancer

Registered User.
Local time
Today, 03:36
Joined
Oct 29, 2004
Messages
290
I have a form with about a dozen command buttons that open forms.

My customers are asking if I can make the command buttons a different color if there is any data in the form the command button opens.

They would like the color to remain changed forever once data is entered.

Any suggestions?

Thanks,
Dave
 
Actually I was looking for something like:
cmdClaimAllowance.ForeColor = #ED1C24
That doesn't work, YET...
 
This changes the color, but will not stay when you close and reopen.

cmdClaimAllowance.ForeColor = RGB(255, 125, 0)
 
Me!cmdname.ForeColor = 0

turns it black. I have not seen a forecolour entered as you have it.

But if you want code to change it on a permanent basis then the only way I know is to have the form open first in design view and I think that will need the code to run from another form.
 
Check the recordsource for a given form, and if it has at least one record, change the color of its command button, something like this, on your "dashboard form":
Code:
Private Sub Form_Activate()

 If DCount("*", "ClaimAllowanceFormRecordSource") > 0 Then
   cmdClaimAllowance.ForeColor = RGB(255, 125, 0)
 Else
   cmdClaimAllowance.ForeColor = -2147483630 'Standard fore color
 End If
 End Sub

Placing the code in the Form_Activate event insures that when the first record is entered, the button will immediately change color upon returning to your dashboard form. If the records in a form are all deleted, the button will change back to the default color.

Repeat this, of course, for each command button.
 

Users who are viewing this thread

Back
Top Bottom