change color scheme in VBA

F

Florin

Hi,
I'm using Access 2007.
I'm trying to change the Office color scheme from VBA. I'm completely hiding
the ribbon so I can only do that from code.

I'm using right now a code that is changing a registry entry.
Unfortunately I need to restart Access for this option to take effect.
Any idea how to do this better?

This is the code right now:

'-----------------------------------------------------------------------------
' Utilities from http://blog.nkadesign.com/microsoft-access/
' (c) Renaud Bompuis, 2008
' Licensed under the Creative Commons Attribution License
' http://creativecommons.org/licenses/by/3.0/
' http://creativecommons.org/licenses/by/3.0/legalcode
'
' Free for re-use in any application or tutorial providing clear credit
' is made about the origin of the code and a link to the site above
' is prominently displayed where end-user can access it.
'-----------------------------------------------------------------------------

Option Compare Database
Option Explicit

'-----------------------------------------------------------------------------
' Enums to easily refer to the correct color scheme.
'-----------------------------------------------------------------------------

Public Enum OfficeColorSchemes
InvalidScheme = -1
BlueScheme = 1
SilverScheme = 2
BlackScheme = 3
End Enum

'-----------------------------------------------------------------------------
' Set MS Office to the given Color Scheme.
' Use WarnUser:=false to disable the notification
' The change is not immediate and will only be effective after the
application restarts
'-----------------------------------------------------------------------------
Public Sub SetOfficeColorScheme(scheme As OfficeColorSchemes, Optional
WarnUser As Boolean = True)
On Error GoTo ErrLbl

If scheme = OfficeColorSchemes.InvalidScheme Then Exit Sub
API_Registry.RegSetValueNum API_Registry.HKEY_CURRENT_USER,
"Software\Microsoft\Office\12.0\Common\", "Theme", scheme

If WarnUser Then
Dialog.Box "The change will take effect the next time" & vbCrLf &
"the application is launched.", vbOKOnly + vbInformation, "Changing Theme"
End If

Exit Sub
ErrLbl:
If err <> 0 Then MsgBox err.Description & " - " & Erl() & ": " & "
(SetOfficeColorScheme)", vbCritical, "Error"
End Sub


Thanks!
Florin
 
G

Gina Whipp

Florin,

I do not know if there is another way to do but I am curious why you are
changing the color scheme that the User selected as it will change it for
the Office 2007 suite. (Unless there was some update I did not get.) I
would a little annoyed if somone changed my color scheme everytime I opened
a Access database they created. You can make the forms whatever color you
like, so why change the color of the Offices 2007 suite?

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
F

Florin

Thanks Gina,
My application is a runtime Access front-end. As such, the end user might
have or not Microsoft Office 2007. In case they don't have it they obviously
can't change the color scheme and I don't want them to get stuck with the
default one.

I hope this makes sense.
If you remember the other way to change the scheme please let me know.
Thanks again!
Florin
 
G

Gina Whipp

Florin,

I see your point but what if they do?

Also, I did a search and so far I only see that way. It appears like most
programs since the color is set at start up of the application changing it
would require reinitializing. It is the program you are trying to change
the color of not just the forms.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
F

Florin

My entire application has custom interface options: colors, fonts, backround,
even background images, gradients for header/footer and highlighting for the
buttons on hover. These apply to the forms themselves.
If I can give the option to change the color of the application window as
well, I don't see why I shouldn't.
The more pleasent environment, the better the work.
Thanks again for your help!
F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top