 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 26th, 2006, 10:38 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Error in assigning "TopMargin" property
Can anybody tell me how can I set the value of "TopMargin" property of a control at runtime from VBA module?
I always got error when using:
objControl.Properties("TopMargin")=0.05
Hope that everyone can help soon.
Regards,
========
mKhmer
|
|

March 26th, 2006, 10:46 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
(^_^)
|
|

March 26th, 2006, 11:23 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
I suspect its 'cause the location of the display info is measured in twips per inch. So declare a constant to convert inches to twips, then use it like:
Code:
Private Sub Form_Load()
' used to convert inches to twips
Const twipsPerInch As Long = 1440
Dim objControl As Control
For Each objControl In Me.Controls
With objControl
Select Case .ControlType
Case acLabel
.Properties("TopMargin") = 0.25 * twipsPerInch
Case acTextBox
.Properties("TopMargin") = 0.05 * twipsPerInch
End Select
End With
Next objControl
End Sub
0.05 * 1440 would place your display info 72 twips from the top edge of the control.
HTH,
Bob
|
|

March 27th, 2006, 12:15 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well, I got the point of that TwipsPerInch. Thank you.
But, I still get the error of:
You entered an expression that has an invalid reference to the property TopMargin.
witht below code:
ObjControl.Properties("TopMargin") = 0.05 * twipsPerInch
Thank you,
|
|

March 27th, 2006, 12:19 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
What type of control does the objControl variable refer too? Need to see more of your code.
Bob
|
|

March 27th, 2006, 12:24 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Is objControl set correctly to an instance of an object that supports the TopMargin property?
Bob
|
|

March 27th, 2006, 12:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
I can reproduce your error (2455) if I try to set the TopMargin property of a control (like a commandbutton) that doesn't support the TopMargin property. The only objects that do are textbox, label, and printer objects.
Bob
|
|

March 27th, 2006, 12:44 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I see, it sounds like that error is happened when I tried to work with Command Button, let me try to remove them out of command button.
Thank you....and I will report how it work later.
|
|

March 27th, 2006, 12:58 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ya!!!
You are right....I got it done now.
Big Thank "BOB"
|
|
 |