473,382 Members | 1,086 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How do I Move Objects using VBA code and also, once the objects are moved, how do I m

10
I'm building forms and reports using Mircrosoft Access. I've ran into this issue a few times now and I'm tired of working around it. I need to be able to move objects by changing the left and top position in an access report/form. This is an example of my code. I've tried declaring variables as variant, long, integer, and double. Should I just keep rotating through the different types or is there a better way of doing this? When the form/report opens, the object just goes to zero and the value shown in properties is "0.0028"

Public Sub Form_Load()
Dim lngTop As Long
Dim lngLeft As Long

lngTop = 4.4
lngLeft = 4.4
With Forms!frmTest!Label0
.Left = 4.4
.Top = 4.4
End With
End Sub
Dec 19 '16 #1

✓ answered by PhilOfWalton

You need to use twips as the unit of measurement.
There are 567 twips per cm
There are 1440 twips per inch.

Assuming you are using English measurements, for clarity I tend to use code like this:-
Expand|Select|Wrap|Line Numbers
  1. Public Sub Form_Load()
  2.     Const TwipsPerInch = 1440
  3.  
  4.     With Forms!frmTest!Label0
  5.         .Left = 4.4 * TwipsPerInch
  6.         .Top = 4.4 * TwipsPerInch
  7.     End With
  8. End Sub
  9.  
Phil

8 4111
PhilOfWalton
1,430 Expert 1GB
You need to use twips as the unit of measurement.
There are 567 twips per cm
There are 1440 twips per inch.

Assuming you are using English measurements, for clarity I tend to use code like this:-
Expand|Select|Wrap|Line Numbers
  1. Public Sub Form_Load()
  2.     Const TwipsPerInch = 1440
  3.  
  4.     With Forms!frmTest!Label0
  5.         .Left = 4.4 * TwipsPerInch
  6.         .Top = 4.4 * TwipsPerInch
  7.     End With
  8. End Sub
  9.  
Phil
Dec 19 '16 #2
MrHuth
10
Thanks PhilOfWalton. I've been doing dba stuff for 7/8 years and never heard of this. Thanks for the help.
Dec 19 '16 #3
MrHuth
10
Oh fail. Is there a way to make the changes on said form/report permanent?
Dec 19 '16 #4
PhilOfWalton
1,430 Expert 1GB
How confusing!!!
Your original question was about dynamically moving a control as the form opened (Incidentally, I think it might be better to run the code on the OnOpen event rather than the OnLoad event)

Your second question asks how to position the control permanently.This, as I'm sure you are well aware, is done in Design View (Positionig here is done in Inches or Cms. - NOT Twips) and you don't need the code.

Am I missing the point of your question?

Phil
Dec 19 '16 #5
MrHuth
10
I apologize. I have about 800 objects on a single report. they are in sets of 4. and the position of each set is determined by 1 of those 4. I am unsure of how much time I've spent moving every single object and if I were to use a loop to position each set accordingly, it'd save me days.
Dec 19 '16 #6
MrHuth
10
Just a quick pic fo the dashboard with the kajillion objects.
Dec 19 '16 #7
PhilOfWalton
1,430 Expert 1GB
That looks fun.

This bit of code may give you a clue to redesigning forms/reports.
Note that it is run from an individual module.
Expand|Select|Wrap|Line Numbers
  1. Function RedesignReport(ReportName As String)
  2.  
  3.     Const TwipsPerCm = 567
  4.  
  5.     DoCmd.OpenReport ReportName, acViewDesign
  6.  
  7.     With Reports(ReportName)
  8.         .Text2.Top = 2 * TwipsPerCm
  9.         .Text2.Left = 2 * TwipsPerCm
  10.     End With
  11.  
  12.     DoCmd.Close acReport, ReportName
  13.  
  14. End Function
  15.  
I presume you are aware that if your controls have a consistent form of naming like "loom0101", "loom0102" etc., you can refer to them using indexes.

if you have integers i & j then for i = 1 and j = 2, "loom0102" can be addressed as
Expand|Select|Wrap|Line Numbers
  1.     Me.Controls("loom" & Cstr(Format (i,"00")) & Cstr(Format (j,"00"))
  2.  
Might give you the option to create a table to build your form

Phil
Dec 20 '16 #8
MrHuth
10
Thanks a bunch. I'll have to look into it some more but just being able to move the objects for now is weight lifted off of my shoulders. When I get the 1st version out, I'll start playing around with the module and let you know how it goes. Thanks again.
Dec 20 '16 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Chinook | last post by:
Using code objects? =================== As an OO exercise I have a factory pattern that returns class objects that each have an "action" method. ClassObj.action() in turn returns a code object...
2
by: Himaxda0 | last post by:
Is it possible to access Objects like (document.form1.textfield1) with a string variable like (var obName='textfield1') and using (document.form1.obName.value)? Ive tried it in IE but the value in...
6
by: Dixie | last post by:
Is it possible to use VBA to turn off the View Hidden objects and System objects? dixie
8
by: Robson Machado | last post by:
Dear friens, Does anybody knows how to move controls (images, textboxes, buttons, etc..) using CodeBehind? Regards,
4
by: Steve Schroeder | last post by:
See: http://support.microsoft.com/default.aspx?scid=kb;en-us;317719 I can convert the sample code to my needs for the most part, where I'm fuzzy on is: ...
6
by: rdemyan via AccessMonster.com | last post by:
Is there a way, in code, to move a shelled application on the screen. I've got the shelled app to open and it centers itself. I would like to move it to the right using code, but I don't know...
7
by: ApexData | last post by:
Hello I currently Link the FE/BE using the LinkTables Option and the Linked Table Manager. Any time I need to move the BE to another location, I have to go through this process over again. I...
0
by: hypeartist | last post by:
I need to create interface "on-the-fly" so it "reflects" some class (mainly it's properties). Here's how I do this: public class Transformer { private const TypeAttributes...
2
by: Veloz | last post by:
Hiya My question is whether or not you should associated related objects in your software using a scheme of id's and lookups, or wether objects should actually hold actual object references to...
12
by: billw1100 | last post by:
Hi, this is my first post here, so I hope I'm doing it right. After converting an Access 2007 accdb database to accde, the vba code in my modules runs OK, but the code in my class objects (forms)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.