Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the font color on a command button?

Status
Not open for further replies.

ov3rdr1ve

IS-IT--Management
Oct 20, 2004
32
US
I am needing to change the font color on a command button on a different form when there is a status change on another form.

This is what I am thinking of... I am wanting to put this in the ONCURRENT of the form that has the command button.

If the status of objectX on formX = textX THEN
me.commandbutton.fontface = red
else
me.fontface = black

But this is not working?

Any thoughts?

Thanks
Chance~
 
How are ya ov3rdr1ve . . . . .

Have a look at the [blue]ForeColor[/blue] property.

Calvin.gif
See Ya! . . . . . .
 
Yeah, I made a mistake with the fontface property I mean forecolor.

I know how to change the color of the command button, what I dont know how to do is to have a control on another form be the factor in changing the color...

Something like this

If the value of objectX on formX = textX THEN
me.commandbutton.forecolor = vbred
else
me.forecolor = vbblack

Any thoughts?

Thanks
Chance~
 
OK ov3rdr1ve . . . . .

Try this:
Code:
[blue]   If Forms!frmXName!ControlName = "Your Text" Then
      Me!ButtonName.ForeColor = vbRed
   Else
      Me!ButtonName.ForeColor = vbBlack
   End If[/blue]


Calvin.gif
See Ya! . . . . . .
 
The scenario is this... I have a series of command buttons on the main form representing jurors (as the client requested). When you click on a command button you get the juror information ... the client wants to when he chooses a juror and changes information for that juror (changes the juror status) that the corresponding command button text (on the othher form) change a color signifying that this juror has been either accepted (green), declined (red) or possible (blue).

I have everything working on the juror information side (meaning there is a control that contains the information JUROR ACCEPTED, JUROR DECLIEND, and JUROR POSSIBLE... this text cannot be changed, and is being populated correctly in the table.

So now I am trying to make the oncurrent of the main form (containing the command buttons) having the text change colors depending on what criteria is placed in the (jurorstatus) field in the table tblMain...

I hope that makes sense?

Thanks again for the help!
Chance~
 
Yup, I think we've got it... When data on FormB changes, a control property on FormA should also change.

The OnCurrent event for FormA will work fine in setting the ForeColor (or any other property) for your command button when you first navigate to a record, provided: FormB is open when the OnCurrent event fires; the appropriate condition on FormB is met; and you *explicitly* reference FormB as AceMan has done in his example. However, this won't do any good for updating the property when data is changed on FormB (without moving away from the current record and moving back to it, so the OnCurrent event fires again). FormA has no way of knowing when the data on FormB has changed. FormB must tell FormA that the data has changed and change the control property on FormA. The AfterUpdate event of the textbox on FormB that contains the juror status is a very good candidate for this. You can either use the Recalc method of FormA, or explicitly set the control's property. Again, FormA must be open when the event that contains the code fires, and you must explicitly reference FormA. Something like this:
Code:
Private Sub MyTextBox_AfterUpdate()
    Forms!FormA.Recalc
End Sub
Or
Code:
Private Sub MyTextBox_AfterUpdate()
    Select Case Me!MyTextBox
        Case "JUROR ACCEPTED"
            Forms!FormA!btn1.ForeColor = vbGreen
        Case "JUROR DECLINED"
            Forms!FormA!btn1.ForeColor = vbRed
        Case "JUROR POSSIBLE"
            Forms!FormA!btn1.ForeColor = vbBlue
    End Select
End Sub

HTH,

Ken S.
 
p.s. It sounds from your scenario that the textbox containing the juror status is being populated by some other method than directly entering it, or selecting it from a combo.
this text cannot be changed, and is being populated correctly in the table
If so, you'll need to look at the mechanism that is changing the textbox data as the place to add your code to update the command button forecolor - I'm not sure AfterUpdate fires when data is written to a control programatically.

Ken S.
 
another p.s. Is FormB modal, or being opened in dialog mode? If so, the form's OnClose event could be a good place to update FormA.

Ken S.
 
ov3rdr1ve . . . . .

BTW . . . [blue]Eupher[/blue], exact same questions I was waiting for [blue]ov3rdr1ve[/blue] to verify. I thought I posted, but apparently I didn't. Anyway I believe your ontrack and came up with the following:

[ol][li]In the Click event of each button, open the [blue]JurorInfoForm[/blue] with the following line:
Code:
[blue]DoCmd.OpenForm "[purple][b]JurorInfoFormName[/b][/purple]", , , , , , "[purple][b]CommamdButtonName[/b][/purple]"[/blue]
Need a way to know which is the [blue]calling button[/blue], so using [blue]OpenArgs[/blue].[/li]
[li]In the [blue]AfterUpdate[/blue] event of [blue]JurorStatus[/blue] on the [purple]JurorInfoForm[/purple], copy/paste the following line:
Code:
[blue]   Call SetButStatus(Me.OpenArgs, Me!JurorStatus)[/blue]
[/li]
[li]In a [blue]module[/blue] in the [blue]modules window[/blue], copy/paste the following code ([blue]you![/blue] substitute proper names in [purple]purple[/purple]):
Code:
[blue]Public Sub SetButStatus(ButtonName As String, JurorStatus As String)
   
   If IsOpenFrm("[purple][b]MainFormName[/b][/purple]") Then
      Dim Prp As Property, ButtonColor As Long
      
      Set Prp = Forms![purple][b]MainFormName[/b][/purple](ButtonName).Properties("ForeColor")
      
      Select Case JurorStatus
         Case "JUROR ACCEPTED"
            ButtonColor = vbGreen
         Case "JUROR DECLINED"
            ButtonColor = vbRed
         Case "JUROR POSSIBLE"
            ButtonColor = vbBlue
         Case Else
            ButtonColor = vbBlack 'Delault
      End Select
      
      Prp = ButtonColor
      
      Set Prp = Nothing
   End If

End Sub

Function IsOpenFrm(frmName As String) As Boolean
   Dim cp As CurrentProject, Frms As Object
   
   Set cp = CurrentProject()
   Set Frms = cp.AllForms
   
   If Frms.Item(frmName).IsLoaded Then
      If Forms(frmName).CurrentView > 0 Then IsOpenFrm = True
   End If
   
   Set Frms = Nothing
   Set cp = Nothing

End Function[/blue]
[/li][/ol]
[purple]Thats it![/purple]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top