Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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
 
Old March 26th, 2006, 10:38 PM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ysiline Send a message via Yahoo to ysiline
Default 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
 
Old March 26th, 2006, 10:46 PM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ysiline Send a message via Yahoo to ysiline
Default

(^_^)
 
Old March 26th, 2006, 11:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

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
 
Old March 27th, 2006, 12:15 AM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ysiline Send a message via Yahoo to ysiline
Default

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,

 
Old March 27th, 2006, 12:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

What type of control does the objControl variable refer too? Need to see more of your code.

Bob

 
Old March 27th, 2006, 12:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Is objControl set correctly to an instance of an object that supports the TopMargin property?

Bob

 
Old March 27th, 2006, 12:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

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

 
Old March 27th, 2006, 12:44 AM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ysiline Send a message via Yahoo to ysiline
Default

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.


 
Old March 27th, 2006, 12:58 AM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ysiline Send a message via Yahoo to ysiline
Default

Ya!!!

You are right....I got it done now.

Big Thank "BOB"






Similar Threads
Thread Thread Starter Forum Replies Last Post
error - Object doesn't support this property jamara VBScript 1 September 10th, 2006 05:13 AM
Checkbox Property Error twsinc Access VBA 6 February 10th, 2006 05:43 AM
Invalid use of property error. Bob Rupp BOOK: Beginning Access 2003 VBA 1 March 4th, 2005 09:09 AM
Error in Correlation Property Initialization vijay_rb Biztalk 1 August 17th, 2004 08:17 AM
Invalid Use of Property Compile Error dubs70 Access VBA 8 March 9th, 2004 03:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.