Moving objects on form (6 Viewers)

DakotaRidge

New member
Local time
Yesterday, 17:09
Joined
Jul 21, 2025
Messages
14
I have a form in one of my databases that has a map of the USA. The map shows the states where foods have been recalled by the federal government or the producer.

I would like to know the most efficient way to physically move the state labels and checkboxes from the upper left corner of the form to their normal positions on the map. I tried the .Move function, but that method requires entering 200 four-digit values into VBA. That's not a real problem unless I need to move the map in the future. That could be necessary if I add more attributes to the form. The table has 80 fields now. The fields store data such as the number of deaths and hospitalizations due to contaminated or mislabeled food products.

I can also hide and unhide the labels and checkboxes. But what is the most efficient way to do this?

Thanks.

1753394492102.png
 
Store the X and Y position in a table. I will post an example allows drag and drop of the lables.
 
Use the control top and left properties.

You can use code to drag the control to where it is required in the control mouse move event. Then in the mouse up event update a table with the control name, top and left values

Alternatively select a control by clicking on it, get the control name then click on the map where you want to be. Update table as before
 
I have all the code to do this. If you send me a map you want to use. I can code all the labels faster then I can explain the code.
It would generate the 50 labels. You then drag them one time into position and they would be saved dynamically.

If you want to see a demo of this.
To see a demo of this with lots of dynamic labels see my presentation at 45min.

Here is some code to do this. Yours is far simpler because the number of labels is set.

The code I am demoing in the video is a better representation since it uses labels and not images.
 
Store the X and Y position in a table. I will post an example allows drag and drop of the lables.
Thanks,

Below is what my .Move statements look like. This is for Georgia's label and checkbox.

GA.Move 8.5417, 3.0833, 0.2083, 0.2396 ' Checkbox
LGA.Move 8.5417, 3.0833, 0.2083, 0.2397 ' State label

Determining the Top, Left, Height, and Width values for all 50 states will be a pain if I have to do this several times.

It will be even worse if I want individual objects to move from the top of the form to geographic region A to region B and then to region C. Region A could be states in the western US, region B could be states in the central US, and so forth.

I would like to do that using the method that Alessandro Grimaldi showed at DevCon 2020, if possible. That is to say, I want the form to be animated. My alternative solution is to use .Visibible=False and =True.

In Alessandro's presentation, ships moved in the Mediterranean Sea from northern Italy to Sicily carrying cargo. I was extremely impressed with his presentation because someone earlier said that Access couldn't do animation.
 
I was fascinated by @MajP's job on drag and drop items on forms in the following two thread.
In each case, Drag a circle in the left side of the form with your right mouse button and drop it on the floor plan or the ship. Then select the color.



Risk.jpg
ship.png
 
Determining the Top, Left, Height, and Width values for all 50 states will be a pain if I have to do this several times.
In my method this would take about 5 minutes. Just drag the label into position and it will save it to the correct location to the table. Now you just read the table to move to that state. Once you drag them once you know the label position for each state. For the checkboxes I would just put them below or right of the x.

tblPosistions
-- StateLabel
-- Xpos
--YPos
-- CheckPosition

I will see if I can do a quick demo.
Can you clarify the requirement more?
At the top left of the form are you going to have all the states or some states?
Are you clicking on a state and then showing something on the map?
Why would you not simply show and hide what is in the state? Not sure I understand what is moving since I see labels and checkboxes already.

Regardless you should not be writing this information in VBA, it should be in a table. You vba should be relatively short to do this.
To animate see what is possible. I physically drag, but I think you could simply replicate that movement by a timer and move command.

Again, if you send the form I can demo this much faster than trying to explain it.
 
The table has 80 fields now. The fields store data such as the number of deaths and hospitalizations due to contaminated or mislabeled food products.
You may want to look at your table structure. 80 fields seems excessive for this type of data. If you find yourself adding extra columns from time to time this definitely points to non-normalized data.
 
Hi, I think you are David, right? I recognize your Food Recall program.
Welcome to AWF.
 
To see some animation in access, here are some Heuristic solutions to the Traveling Salesman problem. You can watch the solutions unfold.

1. Add all the capitals to your selected cities in yellow
2. These are improving algorithms so you can start with Closest neighbor, then 2 opt Swap, then 3 opt etc. They all demo some animation of the building of the solution. Yours would be some version of that code.
traveling Salesman.PNG
 

Attachments

Thanks Pete.

I am trying to have the labels and checkboxes for the states physically move to their normal positions on the map. It is like what you would see in a PowerPoint animation. I saw Alessandro do this in 2020 at DevCon.

The label and checkbox for California would move from the upper corner of the form to where California is on the map. Then the two objects for for Oregon would move into their positions, and so on.

I want Access to move the objects using an order based on instructions it gets from the data or the user. For example, if the severity of an illness is extreme, then every recall with that severity should move into place from the West Coast to East Coast.

Recalls for very severe illnesses are classified as Class 1 by the government. Less severe illnesses are classified as Class 2. If a person gets a Class 1 illness he/she could be hospitalized for weeks or die. I may want Class 1 recalls to be displayed using command button, all Class 2 recalls to use another button, and then all Class 3 recalls to use another button. I am likely to use different speech statements with each of the three buttons.

I can use a query to order records using their Class, number of hospitalizations, and deaths. I could also order the states using population data or some other measure or metric.

So yes, the labels and checkboxes for all of the states need to be on the form. I may also want the checkboxes to be different sizes based on the classification of the recalls or some special metric.

When a user clicks on a box, it changes into a checkbox. I use checkboxes because Access will count them on the map using criteria used in the form.

I may also use conditional formatting to flag recalls that are more geographically dispersed. So if 40 or more boxes are checked, a box with a red background may be red while one with only 5 checks could be light green. Again, speech could be tied to the visual indicators.
 
Yes, George. I am still working on the Food Recall form. I think of something new to add to it almost every day.
 
Sorry about that Mark.

My tables often have lots of fields, but some have more than 200 fields. If I fully normalized my databases, I would hit the limit of objects allowed by MS. I have one application now that has more than 4,000 forms, 4,000 reports, and almost that number of tables. That database also has 28,000 queries.

The table behind this form has 80 fields because there is a field for each state plus fields for other attributes. The main reason for this number is that I need to position labels and checkboxes on maps and other objects precisely. That is the reason for this thread.

The other fields on this form include descriptions of symptoms associated with various illnesses and the names of grocery stores that sell a recalled product (e.g., eggs, meat, berries). Descriptions are often short text, but sometimes they are long text fields. The textboxes also have to be correctly positioned on forms and reports. And as I mentioned above, text-to-speech is used to read selected information from this form. This requires de-normalization. I would love to have a database with DKNF, but I just can't create one here.
 
My tables often have lots of fields, but some have more than 200 fields. If I fully normalized my databases, I would hit the limit of objects allowed by MS. I have one application now that has more than 4,000 forms, 4,000 reports, and almost that number of tables. That database also has 28,000 queries.
with those numbers, sad to say, it will soon, and you need to backup often.
 
Sorry about that Mark.

My tables often have lots of fields, but some have more than 200 fields. If I fully normalized my databases, I would hit the limit of objects allowed by MS. I have one application now that has more than 4,000 forms, 4,000 reports, and almost that number of tables. That database also has 28,000 queries.

The table behind this form has 80 fields because there is a field for each state plus fields for other attributes. The main reason for this number is that I need to position labels and checkboxes on maps and other objects precisely. That is the reason for this thread.

The other fields on this form include descriptions of symptoms associated with various illnesses and the names of grocery stores that sell a recalled product (e.g., eggs, meat, berries). Descriptions are often short text, but sometimes they are long text fields. The textboxes also have to be correctly positioned on forms and reports. And as I mentioned above, text-to-speech is used to read selected information from this form. This requires de-normalization. I would love to have a database with DKNF, but I just can't create one here.
Volcanics @ UA, right? :unsure:
 
It will be even worse if I want individual objects to move from the top of the form to geographic region A to region B and then to region C. Region A could be states in the western US, region B could be states in the central US, and so forth.
add an "anchoring point" in your map. you can add 50 invisible label controls on each States on your map.
name them same as the State Abbrev they are in, eg: "lblWA".
then you can just "move" your labels/checkbox to the "anchoring point"

if checkbox WA (chkWA) is checked and want to move it:
Code:
With Me.chkWA
   .Top = Me("lblWA").Top
   .Left = Me("lblWA").Left
End With
 
Any reason for using two objects? Why not one? You can simulate a checkbox with a character to appear in a label caption or an image on a button. Simple code required to change from true to false

If they have to be separate for some reason, associate the checkbox with the label by relative position.

Not tested but if you have stored longitude and latitude values of each location these could be converted to top/left values by identifying an anchor point on your map and a scale - so for example you could ‘zoom in’ to a specific state

I use a similar technique for an estimating app where the user has an image of a building project where they can draw rectangles and lines and other shapes as quasi objects to be associated with a material such as a window, wall, floor etc. They can zoom in and out of the image and scroll and the objects adjust accordingly. So I know it can be done

you might also want to look at using a web control- I saw a demo at the Vienna conference a few years ago where the presenter used a web control to display a map for showing building plots and highlighting their boundaries with more detail as you zoomed in. Much better than mine 🙂

@isladogs also has something around Google maps
 
Thanks, Jack. I learned something new from your post #18. I read recently that the entire .Move statement is not necessary, but I haven't tried it yet.

I use two objects so they can be controlled separately. I have one button on the form that hides the labels and another one that hides the checkboxes. And I have buttons that unhide them. I want to have forms that will open with checkboxes hidden when a recall does not apply to a particular state. In that situation, the user will have to indicate that the FDA or the CDC has updated a recall notification. That happens when a recall spreads from the initial number of states into other regions. That happened recently for some reason. Some contaminated food gets shipped out of state or the government discovers that its information is not accurate.

The idea of zooming in on an object would be useful in a different application. In mine, an entire state is considered to be in danger. However, you have given me an idea. I can have forms that zoom in on the Northeast, where there are so many very small states that it is difficult to show them on my map. The map actually does not show one state in the Northeast because I failed to digitize it. It is so small, I totally missed it.

Has that web control been deprecated? I am running 365, and I try to stay away from anything that MS may kill off. Or should I say MS-AI?

I don't do Google Maps. I tried it once, and it sent me to the wrong location. I would remove Google from my phone but it is the OS. I hope MS brings back the Windows Phone one day,

FDA and CDC do not publish the lats and longs for recalls. Hopefully, one day they will provide the physical addresses for stores that have sold contaminated food products. I would like to know which stores to avoid where I live. That information would tell me a lot about the management. I visited a store recently, and one of the employees was inside coughing. I left the store.
 
Thanks arnelgp.

I will try using that today. Can I get rid of the With and formatting? I have 50 states on the map. I may want to move all of the labels and checkboxes off the map if there are no recalls in a state.

And with so many recalls being announced, I suspect the government will start lifting recalls state by state. It may even start announcing recalls state by state. Now those will be good things to do! But it won't happen with fewer and fewer USDA and CDC personnel.
 

Users who are viewing this thread

Back
Top Bottom