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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Graphical command button 2

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,529
US
I have a form with a few controls, one of them is a command button. Since I want those controls to reflect the number of records in the table in my DB, I started them with Index = 0 and I load as many controls as I need in the code, something like:

[pre]
For I = 1 To rst.RecordCount
Load cmdSQL(I)
With cmdSQL(I)
.Left = cmdSQL(1).Left
.Top = cmdSQL(I - 1).Top + cmdSQL(1).Height + 50
.Visible = True
End With
Next I
[/pre]
That works great.
Now, I need to ‘mark’ some command buttons, so – I figured – I will just change their BackColor property. I did set cmdSQL(0) Style property to 1 – Graphical and I can change its BaclColor just fine, and if I run the code and load all other controls, all command buttons have the new color. Great!

But I don’t want ALL command buttons to change color, I just want certain buttons to do that. So, in the code I have:
[tt]cmdSQL(10).BackColor = vbYellow[/tt][blue]
The color does NOT change. Why not?[/blue]

I can check the Style of this button:
[tt]? cmdSQL(10).Style[/tt]
And I get 0, which is NOT what I set the initial button to.
0 is Standard, 1 is Graphical.


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Ok, so you cannot change Style at runtime - at runtime it is a read-only property.

So you need to ensure that you have set cmdSQL(0) Style property to 1 (vbButtonGraphical) at design time.

And after that it really should work. For example this works exactly as expected om my PC:

Code:
[COLOR=blue]Private Sub Form_Load()
    For I = 1 To 10
        Load cmdSQL(I)
        With cmdSQL(I)
            .Left = cmdSQL(1).Left
            .Top = cmdSQL(I - 1).Top + cmdSQL(1).Height + 50
            .Visible = True
        End With
    Next I
    
    cmdSQL(5).BackColor = vbYellow
End Sub[/color]

Now the thing is, I suspect you know this, and from your description have tried it - and it isn't working. So we just need to figure out what you are doing differently from my very simple working example.
 
strongm said:
what you are doing differently from my very simple working example

[banghead] I was referencing the wrong command button on my Form.
I do have [tt]cmdSQL[/tt], but I wanted to change the color of [tt]cmdTempl[/tt]
I do have an egg on my face now...[thumbsdown]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top