'HorizontalAnchor gives wrong value in Access
The problem: Control.HorizontalAnchor or Control.VerticalAnchor gets a value out of the accepted range.
In the IDE window: Debug.Print Btn.VerticalAnchor --> Result: 4864
In the Immediate window: ?Btn.VerticalAnchor --> 0
Same line. Same code.
I am stumped. Please help.
L.E.: apparently the value somehow gets distorted after
If Btn.HorizontalAnchor = acHorizontalAnchorRight Then
Solution 1:[1]
I got nearly the same issue running Microsoft Access 2013 x64 15.0.5349 (VBA 7.01).
For me the controls HorizontalAnchor property contains the value of the expected AcHorizontalAnchor enumeration plus 25344.
So if the controls HorizontalAnchor is configured to acHorizontalAnchorLeft (0) it contains 25344.
For acHorizontalAnchorRight (1) it contains 25345.
And for acHorizontalAnchorBoth (2) it contains 25346.
Comparing my value 25344 and your value 4864 I can see that their binary representation both contain additionally set bits in the higher byte:
| Decimal | Binary |
|---|---|
| 4864 | 1 0011 0000 0000 |
| 25344 | 110 0011 0000 0000 |
So the workaround I use is to ignore the high byte of HorizontalAnchor:
If (xControl.HorizontalAnchor And &HFF) = _
AcHorizontalAnchor.acHorizontalAnchorLeft Then _
Debug.Print "-> Left"
If (xControl.HorizontalAnchor And &HFF) = _
AcHorizontalAnchor.acHorizontalAnchorRight Then _
Debug.Print "-> Right"
If (xControl.HorizontalAnchor And &HFF) = _
AcHorizontalAnchor.acHorizontalAnchorBoth Then _
Debug.Print "-> Both"
It should be similar with VerticalAnchor.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Unhandled Exception |
