Solved Ampersand in Page.Caption Right-Justifies Its Text

riktek

Member
Local time
Today, 10:35
Joined
Dec 15, 2023
Messages
124
I observed the same behavior in A2007 several years ago and while some weren't able to replicate it, others then confirmed it to be a bug across many Access versions (A2007-A2013) that actually destabilized Access. Today, it manifested in A2019.

To review, we all know that an ampersand (&) in a Caption property designates the immediately following letter as the accelerator key for that object. This is true for Page.Caption (for TabControl pages), specifically.

The problem, which manifested again today on a form that had not previously exhibited it, is that including an ampersand in Page.Caption right-justifies the caption text in the page's tab. Removing the ampersand re-centers the caption text on the tab.

I recall having seen in passing since my initial post, a comment somewhere to the effect that the Caption property for Page objects somehow required special, unique configuration notwithstanding its documentation being indistinguishable from that of other objects' Caption properties. I recall having bookmarked the comment expressly but now can't find it.

I wonder who else is aware of this bug, what its cause or the/a fix might be, and in particular whether anyone is aware of the ephemerally, long-ago noted special handling for Page.Caption that somehow fixes this. I'd be most grateful for any/all constructive input.
 
This is a screenshot from the Northwind 2 Dev Edition, Product form. I don't see the issue you're raising, but because of the tight cropping there is not much difference between a right aligned and a center aligned tab.
Post your screenshot, please.
1751761579682.png
 
If you want to use certain special characters such as the & in a label, you need to double it up. Use && and that will just show the &. Which probably means that you can't make the & underlined as Tom's example shows. This isn't a bug. It is a "feature".
 
If you want to use certain special characters such as the & in a label, you need to double it up. Use && and that will just show the &. Which probably means that you can't make the & underlined as Tom's example shows. This isn't a bug. It is a "feature".
Looks like you missed the point, Pat.

I think the OP wants the underline and the ability to use the accelerator key. They just don't want the side effect that the caption then becomes right-aligned.
 
I think the OP wants the underline and the ability to use the accelerator key. They just don't want the side effect that the caption then becomes right-aligned.
That isn't the way I read the question.
 
@riktek
I can't replicate your issue either with ampersands in tab page captions or even with a form caption in tabbed documents display.
Whatever I try, the captions are always centre aligned:

1751830630775.png
 
I see it in A2K7

Screenshot from 2025-07-06 23-03-18.png


Code behind form:
Code:
Option Explicit
Option Compare Database

Private Sub Form_Load()
  Call TabsFullWidth
End Sub

Private Function TabsFullWidth() As Boolean

  Const SPACER As Long = 50
 
  With Me.TabCtl0
    .TabFixedWidth = (.Width - SPACER) \ .Pages.Count
  End With
  TabsFullWidth = Err = 0

End Function
 
Last edited:
A2007 has been out of support for almost 8 years. There will be no fixes. You will have to upgrade, or live with this.
 
Also in A2007 with no code

1751841581599.png


Despite the caption, both are centred. I tried overlapping windows & tabbed docs, popup & non popup.

Then I added the same code - no change -for me both are still centred!
 
I only use A2007 for occasional testing & there is no code used to hide the ribbon.

I did see something odd however in A2007. I increased the tab ctrl width so that I saw left/right arrows in the page header area.
I then clicked the second tab and the first tab disappeared

That behaviour doesn't happen in A365 as the total of the tab page widths cannot be greater than the width of the control
 
I increased the tab ctrl width so that I saw left/right arrows in the page header area.
That's why I used the constant (SPACER) to calculate the tab widths without requiring the left/right arrows in the code I used.
 
That's why I used the constant (SPACER) to calculate the tab widths without requiring the left/right arrows in the code I used.
It seems this is just one of the many ways that Access has overall improved since the dim and distant days of A2007.
Anyway, I don't know which version of Access that @riktek uses but I can't replicate the issue in the versions I used for testing.
 
If you want to use certain special characters such as the & in a label, you need to double it up. Use && and that will just show the &. Which probably means that you can't make the & underlined as Tom's example shows. This isn't a bug. It is a "feature".
My understanding is that doubling an ampersand escapes it (just as doubling a quoted apostrophe or quotation mark), with the consequence that a single ampersand appears in the caption.

Instead, I'm trying to designate the following character as an accelerator key.
 
This is a screenshot from the Northwind 2 Dev Edition, Product form. I don't see the issue you're raising, but because of the tight cropping there is not much difference between a right aligned and a center aligned tab.
Post your screenshot, please.
View attachment 120470
Here's the problem case:
1751911235533.png

and here's the case omitting the ampersand for the first (leftmost) tab:
1751911182819.png


I will add that, in my prior post on this topic, many at first could not replicate the issue but then others did, going on to discover it introduced unspecified instabilities.
 

Users who are viewing this thread

Back
Top Bottom