Changing Buttons color pragmatically (1 Viewer)

Rakesh935

Registered User.
Local time
Today, 23:51
Joined
Oct 14, 2012
Messages
71
Hi Guys,

I need some of your valuable advice for the below pointers:

1) Would it be a good idea, if I use buttons as indicators.
2) If yes, would it be possible to have two colors i.e. red and green.

Condition:
If the access file has a table named “Working” then the button color should be in green else it should be red.

Thanks,
Rakesh
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:21
Joined
May 7, 2009
Messages
19,169
this can be done on Form's Load Event:
Code:
Private Sub Form Load()
If Me.Recordsource Like "*Working*" Then 
    Me.Button.BackColor = vbGreen
Else
    Me.Button.BackColor = vbRed
End If
End Sub
 

Rakesh935

Registered User.
Local time
Today, 23:51
Joined
Oct 14, 2012
Messages
71
this can be done on Form's Load Event:
Code:
Private Sub Form Load()
If Me.Recordsource Like "*Working*" Then 
    Me.Button.BackColor = vbGreen
Else
    Me.Button.BackColor = vbRed
End If
End Sub

Hey arnelgp,

Thanks for such a quick reply...

I tried this code but I see the color not changing to green although the access file has a table name as Working, and it stays with red only.

Please help.

Thanks,
Rakesh
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:21
Joined
May 7, 2009
Messages
19,169
does your form's recordsource has "Working" on it?
which access file are we talking here, on the navigation pane?
 

Rakesh935

Registered User.
Local time
Today, 23:51
Joined
Oct 14, 2012
Messages
71
does your form's recordsource has "Working" on it?
which access file are we talking here, on the navigation pane?
Apologies, I was not clear in my 1st thread.

Actually, in my access form (Unbound) I have a button to browse and import excel file which is a template. And post importing rename it to Working.

So now, if I have this table "Working" in the access file then the indicator is going to be in green color else it to be in red.

This would be a cycle process, meaning every time a new project is started subsequently a new template would be imported and renamed to Working.

Hope I'm clear now..
 

isladogs

MVP / VIP
Local time
Today, 18:21
Joined
Jan 14, 2017
Messages
18,186
This should work if Working is the name of a local or linked table

Code:
Private Sub Form Load()
If DCount("*","MSysObjects","Name='Working' And Type In(1,4,6)")>0 Then
    Me.Button.BackColor = vbGreen
Else
    Me.Button.BackColor = vbRed
End If
End Sub
 

Users who are viewing this thread

Top Bottom