The colors in the custom colors array don't get saved automatically. You have to do this of your own. You can write them to a file, or in registry, which is preferred and easier as well.
See the code below which is slightly modified verion of the original code. It shows you how to preserve custom colors by writing them in registry.
___
[tt]
Private Declare Function ChooseColor Lib "comdlg32" Alias "ChooseColorA" (pChoosecolor As CHOOSE_COLOR) As Long
Private Type CHOOSE_COLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Const CC_FULLOPEN = &H2
Const CC_RGBINIT = &H1
Dim CustColors(15) As Long
Private Sub Form_Load()
'initialize colors
Dim N As Long
For N = 0 To 15
CustColors(N) = GetSetting(App.Title, "Colors", N, QBColor(N))
Next
Me.BackColor = GetSetting(App.Title, "Colors", "BackColor", BackColor)
End Sub
Private Sub Command1_Click()
Dim cc As CHOOSE_COLOR
cc.flags = CC_FULLOPEN Or CC_RGBINIT
cc.hwndOwner = hWnd
cc.lpCustColors = VarPtr(CustColors(0))
cc.rgbResult = Me.BackColor
cc.lStructSize = Len(cc)
If ChooseColor(cc) Then
Me.BackColor = cc.rgbResult
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim N As Long
For N = 0 To 15
SaveSetting App.Title, "Colors", N, CustColors(N)
Next
SaveSetting App.Title, "Colors", "BackColor", BackColor
End Sub[/tt]
___
Just in case you want to know, the custom colors are save in the following registry location.
HKEY_CURRENT_USER\Software\VB and VBA Program Settings\<App Title>\Colors