Using buttons to enter data in to fields (1 Viewer)

omarrr128

Member
Local time
Today, 14:00
Joined
Feb 5, 2023
Messages
69
Hello,

I hope everyone is doing well.

I have a form that has 2 seperate combo boxes. One is the Start location of a transport job and the other is the end location of it. So the user selects the locations from the drop down list.

Instead I want it to be so that the location names are all buttons on a map. When the user clicks the location name it pops up automatically in the "Start/End Location" field. This saves them having to use the keyboard.

What code would I need to use to make this work? Bearing in mind that once they click the location name it needs to go to the correct field
(the one that was last dirty?)

Thank you
 

XPS35

Active member
Local time
Today, 15:00
Joined
Jul 19, 2022
Messages
159
And what if both are selected and the user wants to change one of the locations?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:00
Joined
Jul 9, 2003
Messages
16,282
And what if both are selected and the user wants to change one of the locations?

I concur, this is not a very well thought through process.....
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:00
Joined
Sep 21, 2011
Messages
14,306
But the control will not be dirty will it, if you just tab out and select a button?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 14:00
Joined
Feb 19, 2013
Messages
16,614
What are you using to display the map? Web control? Image control? Form background ?

also how many locations and are they likely to change? Could be a big cost in maintenance

you can use the mouse events to detect where the cursor is over the button so if the caption is say ‘start/end’ you can determine whether the cursor was over one word or the other - store the location in the tag property and perhaps in the caption as well.

alternatively, again from the mouse events use the button parameter to determine if left or right button was down

and you could use the mouse move event to display the location when the mouse is over the button
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:00
Joined
Oct 29, 2018
Messages
21,473

Gasman

Enthusiastic Amateur
Local time
Today, 14:00
Joined
Sep 21, 2011
Messages
14,306
Most people would select start then end?
However if you give them a way to reverse the selection, they can select in any order?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 14:00
Joined
Feb 19, 2013
Messages
16,614
Here is a simple example using the methods I suggested. Note it only needs one control (a label in this example) rather than multiple labels/buttons

Right click on the map to create a new location - a few have been created.

as you move over the map, when over a created location, the label will appear below the cursor, click to the left or right of the label to add a start or end location as required.

This example uses an image control, pretty sure if you used a web control and google API's you could select locations without previously specifying them.
 

Attachments

  • LocationsOnMap.accdb
    624 KB · Views: 76

omarrr128

Member
Local time
Today, 14:00
Joined
Feb 5, 2023
Messages
69
And what if both are selected and the user wants to change one of the locations?
That is my point. Which is why I mentioned the last dirty field. Maybe that could be used in the vba to say that the location that is clicked is added to the field that is last made dirty. This would allow users to change the locations.
 

omarrr128

Member
Local time
Today, 14:00
Joined
Feb 5, 2023
Messages
69
I concur, this is not a very well thought through process.....
Maybe don't be so quick to judge.

I've obviously thought about that which is why I mentioned the "last dirty field". If possible, that could be used in the vba to say that the location button that is clicked is added to the text box that is dirty. This would allow users to change the locations.

If that is not possible then they could always change the location by manually typing it in.
 

omarrr128

Member
Local time
Today, 14:00
Joined
Feb 5, 2023
Messages
69
The question is how to make it go to either the Start/End location text box that the user wants it to.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:00
Joined
Oct 29, 2018
Messages
21,473
The question is how to make it go to either the Start/End location text box that the user wants it to.
I waited a while to let you finish addressing each post, but you may have missed mine. Did you try it?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 14:00
Joined
Feb 19, 2013
Messages
16,614
also missed mine - post #5. And post #9 which among other things addresses your question in post #13

If no acknowlement in the next 12 hours - I'll delete them as clearly there is no interest in what I have to suggest
 

omarrr128

Member
Local time
Today, 14:00
Joined
Feb 5, 2023
Messages
69
I waited a while to let you finish addressing each post, but you may have missed mine. Did you try it?
Sorry I have just seen it now. Thank you :) it looks like exactly what I'm after.

I will try to implement it and see how it works out :)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:00
Joined
Oct 29, 2018
Messages
21,473
Sorry I have just seen it now. Thank you :) it looks like exactly what I'm after.

I will try to implement it and see how it works out :)
Kindly let us know how it goes. Good luck!
 

omarrr128

Member
Local time
Today, 14:00
Joined
Feb 5, 2023
Messages
69
also missed mine - post #5. And post #9 which among other things addresses your question in post #13

If no acknowlement in the next 12 hours - I'll delete them as clearly there is no interest in what I have to suggest
I have just seen yours too but I wanted to try to implement it first before replying.

It looks great thank you very much for sharing the file. I am just struggling to do it with my database.

Instead of hovering over locations on an image could it work with hovering over text boxes? So the label pops up still?
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 14:00
Joined
Feb 19, 2013
Messages
16,614
@omarrr128 - you appear to respond only to posts you receive a notification about - all I can say is that is a a bad practice and one that will put responders (certainly me) off from responding with alternatives. When you come back to the thread, take care to review and respond to all responses since your last post.

Instead of hovering over locations on an image could it work with hovering over text boxes? So the label pops up still?
Not as such - see post #5. If you want the maintenance involved every time you add or remove a location, then just add the labels at each location and use the code in the label mouse up event and remove the code for the image events. The right click code I provided to add locations was just for demo purposes to add locations so (I suspect) can be ignored. You can use a textbox or a button instead of a label, but they come with additional requirements. And no need for a label to popup since you are (presumably) displaying the same information, just add the code to your textbox of button instead

Your requirement is quite vague so far - what is a map? - a town?, a country?, a continent? the world? or something else? What defines a start or end location? Why do you need a button (or textbox or label) for each location. Answer these questions and everyone might get some clarity on the actual requirement.

Recommend you provide context by describing the business and the purpose behind the requirement. My example provides discrete broad base locations but probably not suitable if one location if '1 Carnaby Street' and '2 Carnaby Street' are considered to be different locations - but that also depends on the scale of the 'map'.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:00
Joined
Feb 28, 2001
Messages
27,186
There is a general rule in Access programming and you just ran afoul of it. (The general rule is: "If you want something unusual or specific done, you probably will have to do it yourself.") "Last dirty control" is not supported by Access. You have to somehow tag a field to know when it became dirty because Access neither offers a sequence number nor a time tag regarding WHEN something becomes dirty. You would have to maintain that "dirty order" yourself using VBA.

Now, the kink in the garden hose... If someone dirties a control, you can find it via comparison between .OldValue and .Value - but there is no Direty flag on controls. "Dirty" is a FORM property. So, if you haven't saved anything yet and try to dirty a second control, in the absence of an order tag, you have no easy way of knowing which control got dirty most recently by scanning. You would see EVERY CONTROL if you don't track the time of dirtiness. You have to tag the control when it gets dirty - perhaps using either the Change event or the LostFocus event as the event that tracks this for you. You would need to implement such events on each potential control that would have this ability. BUT doing this via programming doesn't fire the Change event for textbox controls - it only triggers on manual input.

Then, there is this question... are you putting the cart before the horse here? You want to click a button to load the control that just got dirty... but it wouldn't be dirty until you actually loaded something to it, would it? From the way you described it, you are doing things in the wrong order. So let's say you select a control that you wanted to load via this putative button. BUT ... the MOMENT you click that button to load the value to the selected control, you change focus and select the button you just clicked BEFORE THE OnClick event fires - with the code having no memory of what control was previously selected, unless you "roll your own" log of control selections.

Now, you can say that you didn't mean it that way, but I'm telling you how I reacted to what you described to us. So if I got confused enough to misunderstand what you are doing, I apologize. But I'm telling you what it looked like you were doing.
 

Users who are viewing this thread

Top Bottom