status of buttons

let's say i have 60 command buttons in a form.
And i would like to save the settings for each one (e.g. caption, backcolor )

how would i be able to do that ?
Who is Participating?
BeedleGuisConnect With a Mentor Commented:
dim ctrl as control
dim cntrls as new collection
private type buttn
   Caption as string
   Color as string
end type
for each ctrl in me.controls
    If TypeOf ctrl Is CommandButton Then
        buttn1.caption = ctrl.caption
        buttn1.color = ctrl.backcolor
        cntrls.add buttn1
    end if
next ctrl

Depending on where you want to save them .. collection or text file or whatever
cyberpAuthor Commented:
let's say i wanna do it in a text file.

how i i read and write the settings to the file.
And load it later when the form loads.
cyberpAuthor Commented:
btw, each buttons may have different settings. Different caption and colors.. so ?
Open "C:\BTNS.TXT" For Output As #1
Dim ctrl As Control
Dim cntrls As New Collection
For Each ctrl In Me.Controls
    If TypeOf ctrl Is CommandButton Then
        Write #1, ctrl.Caption & "," & ctrl.BackColor
    End If
Next ctrl
Close #1

Then to restore:

Dim strcap As String
Dim strbackcolor As String
Dim ary() As String

Open "C:\BTNs.TXT" For Input As #1
For Each ctrl In Me.Controls
    If TypeOf ctrl Is CommandButton Then
        Input #1, strcap
        ary = Split(strcap, ",")
        ctrl.Caption = ary(0)
        ctrl.BackColor = ary(1)
    End If
Next ctrl
Close #1
End Sub

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.