Changing button format depending on related records

ibbledibble

Registered User.
Local time
Today, 22:57
Joined
Sep 29, 2008
Messages
59
Hello

I have a DB with a Customer table that has a 1-to-many relationship with other tables. Each of these sub-tables are accessed through control buttons on the form of the customer table.

What I want to do is change the colour of the control button when there is data in the related record.

Is this possible?

Thanks!
 
Right, that should be ok then.

Put something like this in the On Current event of the Form:
Code:
If DCount(...) > 0 Then
     Me.NameOfButton.ForeColor = vbRed
Else
     Me.NameOfButton.ForeColor = vbBlack
End If
An idea too will be to add a count to the caption of the button in brackets so a typical caption would be:

Open Record (32)
 
note that you can change the text colour of a button, but not the background.

you can change the text as well, if you wish.
 
Thank you very much for the suggestions...

One more question - would this work for counting data in a related record? I don't want to check there is data in the whole of the related table, just in the specific record that relates to the customer page I am viewing.

The data is linked by the primary key of the customer table.

Thanks (hope I'm being clear).
 
Solved it!

Private Sub Form_Current()
If DCount("*", "qryYourQuery") > 0 Then
Command42.ForeColor = RGB(255, 125, 0)
Else
Command42.ForeColor = -2147483630 'Standard fore color
End If
End sub
 

Users who are viewing this thread

Back
Top Bottom