CmdButton Color using Laben's tool

  • Thread starter Thread starter Ronald Dodge
  • Start date Start date
R

Ronald Dodge

Help me out if you could please, using Access 2002 as the company has
finally upgraded it's office program.

Steps that I have taken

File was converted to Access 2000 that was downloaded from Leban's web site.

Followed the directions of how to setup the toolbar button on the toolbox
with the only other thing that I did, created an image for it and have it
show the image rather than text, but still left the caption in place.

Exported the module from his file.

Closed out of Access

Opened up Access

Imported the file into my Access file.

Opened one of my forms in "Design View"

Selected a command button that does have caption in it as specified in
Leban's file.

Attempt to use the function on the ToolBox and get the error message,
"Sorry - you MUST be in Form Design View!"

Am I missing something here?
 
Okay, I have found the cause of the issue at hand. If a command button is
on a page of a multi-tab control object, this is when the error message pops
up. Take a look at the snippet of the code that I have pulled out.


Set objFormReport = ctl.Parent
If objFormReport Is Nothing Then
lngRet = MsgBox("Sorry - you MUST be in Form Design View!")
GoTo ErrHandler
End If

'See if we are not in Form Design View
If objFormReport.CurrentView <> 0 Then
lngRet = MsgBox("Sorry - you MUST be in Form Design View!")
GoTo ErrHandler
End If

Now that I have found where the problem lies at and what is causing it, I
resolved the above issue with the following fix:

'Check to see if the Parent object is a page on a multi-tab object.
If ctl.Parent.ControlType = 124 Then
Set objFormReport = ctl.Parent.Parent.Parent
Else
Set objFormReport = ctl.Parent
End If
If objFormReport Is Nothing Then
lngRet = MsgBox("Sorry - you MUST be in Form Design View!")
GoTo ErrHandler
End If

'See if we are not in Form Design View
If objFormReport.CurrentView <> 0 Then
lngRet = MsgBox("Sorry - you MUST be in Form Design View!")
GoTo ErrHandler
End If

Now that I have put in that fix, I'm no longer getting an error message, but
it's still not doing the color bit for me. I will now need to go on down
the code and find the issue.
 
Okay, now that I found the same type problem in the "fCmdButTextPic"
function, I replaced the code:

Set objFormReport = ctlCmdButton.Parent

with the following code:

If ctlCmdButton.Parent.ControlType = 124 Then
If Err.Number = 2465 Then
Set objFormReport = ctlCmdButton.Parent
Err.Clear
Else
Set objFormReport = ctlCmdButton.Parent.Parent.Parent
End If
Else
Set objFormReport = ctlCmdButton.Parent
End If

Both locations needs this fix for it to work with both types of command
button locations.

"On Error Resume Next" must be set for this to work.

With this fix in place, it works for those command buttons on the pages of
multi-tab controls, but not so well for those on forms directly as it sets
the color of the command button to dark gray regardless.
 
Need to revise my last statement a bit. It's when the command button has
it's Enabled button set to "No", that's when the background is showing as
dark gray, of which this is not a desired effect with the letters also being
dark gray.
 
The color used by Access to render a control set to Disabled is not
exposed as a property and is a function of your current Windows
settings.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Back
Top