Solved User made command button that can be moved with mouse? (2 Viewers)

mounty76

Registered User.
Local time
Yesterday, 23:02
Joined
Sep 14, 2017
Messages
341
Hi All,

Not sure if this is possible? I would like a form that has a diagram of some plans on, this is the easy part lol

I would then like the user to be able to 'create a job' and on clicking this button some vba makes a new button (or basically a small red circle) that the user can move around the form so it can be placed over a certain position on the plan, this button then opens a 'Job' form when pressed?

Does that make any sense or is it even worth going down that road?

Basically I'd end up with some drawings/plans with a load of red dots on that when each one is clicked it opens up a job record. I've seen VBA to make a button and position it using Left, right, top, and bottom values but haven't come across anything that could do the above? Not sure if this is possible because the form effectively needs to be edited whilst still in form view.

Any ideas most welcome
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:02
Joined
Oct 29, 2018
Messages
21,473
Very possible but would definitely require some good planning. If you want the behavior persisted, you'll probably need a table to store all the user's input about the circle's position and which record it opens.
 

Edgar_

Active member
Local time
Today, 01:02
Joined
Jul 8, 2023
Messages
430
Additionally to storing the positions, you'd have to have pre-created buttons that you make visible so you avoid:
1. Reaching maximum control number
2. Going into design mode to create the buttons
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:02
Joined
May 21, 2018
Messages
8,529
See example
 

GPGeorge

Grover Park George
Local time
Yesterday, 23:02
Joined
Nov 25, 2004
Messages
1,867
Hi All,

Not sure if this is possible? I would like a form that has a diagram of some plans on, this is the easy part lol

I would then like the user to be able to 'create a job' and on clicking this button some vba makes a new button (or basically a small red circle) that the user can move around the form so it can be placed over a certain position on the plan, this button then opens a 'Job' form when pressed?

Does that make any sense or is it even worth going down that road?

Basically I'd end up with some drawings/plans with a load of red dots on that when each one is clicked it opens up a job record. I've seen VBA to make a button and position it using Left, right, top, and bottom values but haven't come across anything that could do the above? Not sure if this is possible because the form effectively needs to be edited whilst still in form view.

Any ideas most welcome
I don't think he provides his code, but Alessandro Grimaldi has some YouTube videos demonstrating similar techniques. And here.
Also this video on drag-and-drop Gantt Charts.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:02
Joined
May 21, 2018
Messages
8,529
I don't think he provides his code
I do provide the code and demonstrate full drag and drop. However, I do not demonstrate assigning a procedure to the dropped image, but you could easily add that. You would store the job record in the same table as where the positions are stored. I would also store that in the tag property of the button.
clicked it opens up a job record.

The way this works is that you have a set amount of controls stacked on top of each other. I think I have 50. When you drag and drop it that information is stored in a table. When you open the form then for every record it picks a control and moves it to the x and y positions. In this case it assigns the correct image to that control.
This demo is probably more complicated than what is asked since a lot of the complexity was with assigning and changing images.
 

GPGeorge

Grover Park George
Local time
Yesterday, 23:02
Joined
Nov 25, 2004
Messages
1,867
I do provide the code and demonstrate full drag and drop. However, I do not demonstrate assigning a procedure to the dropped image, but you could easily add that. You would store the job record in the same table as where the positions are stored. I would also store that in the tag property of the button.


The way this works is that you have a set amount of controls stacked on top of each other. I think I have 50. When you drag and drop it that information is stored in a table. When you open the form then for every record it picks a control and moves it to the x and y positions. In this case it assigns the correct image to that control.
This demo is probably more complicated than what is asked since a lot of the complexity was with assigning and changing images.
To avoid misunderstanding, let me clarify, "I don't think [Alessandro] includes his code in his videos...."
 

Edgar_

Active member
Local time
Today, 01:02
Joined
Jul 8, 2023
Messages
430
To assign a function to each button, that can either be stored in a table or a tag, and be used with CallByName or something else that the architecture chosen is more compatible with. But it's definitely doable.
 

mounty76

Registered User.
Local time
Yesterday, 23:02
Joined
Sep 14, 2017
Messages
341
See example
Thank you very much for this, much appreciated MajP. Something like this will work well I think, I'll have a go and let you know! I notice in your thread you mention about this not working well when in runtime mode? I was planning to have the FE in runtime mode when I eventually split the DB, will this be an issue?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:02
Joined
May 21, 2018
Messages
8,529
I believe that comment was about something else. This should work since all properties are set at runtime. I think that comment had to do with opening a form in design view and dynamically creating controls. That cannot be done in a runtime or accde.
The trick to this is that you do not create any controls. You have a group of hidden controls and basically grab whatever amount you need. You then show it and move to the location stored in the table. When you "add" a control you basically are just unhiding one of the hidden control and moving it into position. Once in position you save the location and other properties.
 

mounty76

Registered User.
Local time
Yesterday, 23:02
Joined
Sep 14, 2017
Messages
341
If I get time I will see if I can demo. In some ways this will be simpler without the multiple images.
If you can demo what it would look like with an image and buttons that would help.
Would each button open a different job? If so does the use need to see some label on the button showing the job or they will know what the button represents by it location? If it needs a label on it then it may be better doing this with a command button instead of a dot image. If each button represents a different job how do you envision assigning that job to that button? If you look at the form I have to change the image it might have to be done with a popup or prior to dragging it.

Thank you very much for this. I have made a few changes to the attached so it gives you a clearer picture. Basic changes would be

1. I have changed the table layouts to coloured dots that represent various priorities of jobs
2. I have added a Jobs table which would need to be linked to the table where the position is held, JobID should then be a foreign key to the position table
3. I've added deck layout attachment to the tblfloor, whilst I know it is not ideal holding attachments in the db I want to make this flexible so that a user can upload their own deck plans, these need to be shown on the corrosponding decks in the form where they can add the jobs

Hope that makes sense, I did try to change it but without much success before I got stuck 🤦‍♂️ Thank you so much
 

Attachments

  • MajP_POS_4.accdb
    1.7 MB · Views: 70

Mike Krailo

Well-known member
Local time
Today, 02:02
Joined
Mar 28, 2020
Messages
1,044
That's very interesting. You will need to define the overall dimensions of the area that is allowed for an image to be dragged. Right now, I can drag an item outside the boundaries of the rectangle and code fails with Run-time error 2100 "The control or subform control is too large for this location."
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:02
Joined
May 21, 2018
Messages
8,529
Hope that makes sense, I did try to change it but without much success before I got stuck 🤦‍♂️ Thank you so much
I built this off of the Original Posters tables so there is a lot of "junk" that can be removed to make it less specific. I cleaned out the restaurant specific stuff it should be more understandable.
This was just a proof of concept so there is not a ton of thought into this. I never considered different resolutions so this only works now for a given resolution maximized. I do not do a lot of screen resolution stuff, but @isladogs has a lot of code that could be adapted.

The "deck plans" are read from the attachments and then saved to the local folder where the database resides. Then you can switch between the deck plans from the combobox. This allows the user add edit their deck plans. This requires the application to be in a folder with permissions to save the images.

I have not decided how to link the tasks to the dots. I put a subform on the pop up and I envision the ability to add, edit, or assign an unassigned task. (Next version)

Can you create a default button image "Unassigned Priority"? Lets says light grey. This way the user drags a unassigned priority and then has to edit. Now I simply default to the previous color. Then when they pop up the form to edit the button color they will be forced to assign a task. This is how it looks on my screen at my resolution.

ship.png
As I said this is a proof of concept, I have never built a working database using these ideas. So any feedback is appreciated.
 

mounty76

Registered User.
Local time
Yesterday, 23:02
Joined
Sep 14, 2017
Messages
341
This is amazing, thank you. Yes I think having a grey dot as an unassigned job is a good idea then when it is dragged to 'create a new job' the popup frm opens whereby its data entry and forces the user to select all items.
 

mounty76

Registered User.
Local time
Yesterday, 23:02
Joined
Sep 14, 2017
Messages
341
Or another maybe better idea would be to have a subform to the side of the deckplan that just shows the job description of the dot that has focus? That way it would be easier to see just by clicking on the various dots what the job is?
 

Mike Krailo

Well-known member
Local time
Today, 02:02
Joined
Mar 28, 2020
Messages
1,044
When I tried the MajP's sample I got error: Missing file Profile.png
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:02
Joined
May 21, 2018
Messages
8,529
When I tried the MajP's sample I got error: Missing file Profile.png
That was my fault. It should work now. It was calling the image before the attachments were downloade
Or another maybe better idea would be to have a subform to the side of the deckplan that just shows the job description of the dot that has focus? That way it would be easier to see just by clicking on the various dots what the job is?
That would work and simplify things. You could set the color and the Job then drag. I did not know if the real estate existed so did not do that.

If you put a subform the way you like then I can demo that.
 
Last edited:

Mike Krailo

Well-known member
Local time
Today, 02:02
Joined
Mar 28, 2020
Messages
1,044
Yep, that new version works great MajP. This is really interesting how it all works. I'm just worried there isn't enough life rafts on the boat.:D
 

Edgar_

Active member
Local time
Today, 01:02
Joined
Jul 8, 2023
Messages
430
That was my fault. It should work now. It was calling the image before the attachments were downloade

That would work and simplify things. You could set the color and the Job then drag. I did not know if the real estate existed so did not do that.

If you put a subform the way you like then I can demo that.
I just wanted to test it.

In Access 2021, I could not reproduce the drag and drop gesture. I only could delete the items or change their color.

In Access 2016, I could not reproduce the drag and drop gesture easily, it required a few tries.

It's worth mentioning the placing of the items is resolution-dependent.
 

Users who are viewing this thread

Top Bottom