424,301 Members | 1,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,301 IT Pros & Developers. It's quick & easy.

Open MAP, set PushPin, add lat./lng of pushpin to recordset ?

P: 32
I have a database project (in MS Access 2016) and wish to add a mapping feature with the following functionality (via VBA is preferred);

1 – Create a FORM that includes display of a street map of a specific small city overall view (I can get the desired starting URL from Google or Bing maps). This can fill on Open or via a command button.

2 – The user manipulates that map’s controls in order to locate a target point that they desire, and manually MARK (such as by pushpin) that point.

3 – After marking the point they can press a command button which will then acquire the latitude and longitude of the point so marked (pushpin) and store that data in the current recordset. If that marked map image can be stored as a .jpg or similar, that would be a “bonus”.

4 – On the REPORT associated with that recordset, I would like to include a subREPORT that is an image of that map showing that pushpin…… either using the SAVED .jpg image OR created dynamically at Preview/Print so that it appears in the printed REPORT (whichever method is easier to code).
Jul 11 '18 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 2.5K+
P: 2,896
OK - so normally we don't just post a full solution, but trying to describe this one step by step would be nearly impossible.

First, in your VBA Editor, go to Tools, References..., Browse: C:\Windows\SysWOW64\FM20.DLL and add it to your references. It may be in a different location on your machine.

Next, create a new stand alone module named modKeyStrokes:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  4. Public Declare Sub keybd_event Lib "user32" ( _
  5.     ByVal bVk As Byte, _
  6.     ByVal bScan As Byte, _
  7.     ByVal dwFlags As Long, _
  8.     ByVal dwExtraInfo As Long)
  10. Declare Function GetKeyState Lib "user32.dll" ( _
  11.     ByVal nVirtKey As Long) As Integer
  13. Private Const vk_Tab = &H9 'TAB key
  14. Private Const vk_Shift = &H10 'SHIFT key
  15. Private Const vk_Control = &H11 'CTRL key
  16. Private Const vk_KEYUP = &H2 'indicates the key being released
  17. Private Const vk_C = 67
  19. Public Function vkC()
  20.     keybd_event vk_C, 1, 0, 0
  21. End Function
  22. Public Function vkShift()
  23.     keybd_event vk_Shift, 1, 0, 0
  24. End Function
  25. Public Function vkShiftUp()
  26.     keybd_event vk_Shift, 1, vk_KEYUP, 0
  27. End Function
  28. Public Function vkTab()
  29.     keybd_event vk_Tab, 1, 0, 0
  30. End Function
  31. Public Function vkCtl()
  32.     keybd_event vk_Control, 1, 0, 0
  33. End Function
  34. Public Function vkCtlUp()
  35.     keybd_event vk_Control, 1, vk_KEYUP, 0
  36. End Function
Then, in your Form, using a Command Button, place this code in the OnClick Event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdLatLong_Click()
  2. On Error GoTo EH
  3.     Dim objData     As New MSForms.DataObject
  4.     Dim strTemp     As String
  6.     AppActivate "Google Maps", False
  7.     vkShift
  8.     vkTab
  9.     PauseEvent 0.25
  10.     vkShift
  11.     vkTab
  12.     vkShiftUp
  13.     PauseEvent 0.25
  14.     vkCtl
  15.     vkC
  16.     vkCtlUp
  17.     PauseEvent 0.25
  18.     objData.GetFromClipboard
  19.     strTemp = objData.GetText()
  20.     Debug.Print strTemp
  22.     Exit Sub
  23. EH:
  24.     MsgBox "There was an error getting the Lat/Long!" & vbCrLf & vbCrLf & _
  25.         "Error: " & Err.Number & vbCrLf & _
  26.         "Description: " & Err.Description & vbCrLf & vbCrLf & _
  27.         "Please contact your Database Administrator.", vbCritical, "WARNING!"
  28.     Exit Sub
  29. End Sub
  31. Public Function PauseEvent(ByVal Delay As Double)
  32.     Dim dblEndTime As Double
  34.     dblEndTime = Timer + Delay
  35.     Do While Timer < dblEndTime
  36.         DoEvents
  37.     Loop
  38. End Function
With Google maps, I have been unable to place a push pin and have the system recognize that push pin. However, with this method, the user can zoon in to wherever they want and Google Maps will save that view for future use.

ALso note, that this code is finicky at best and frustrating at worst. The user must be in Google Maps, with no bells and whistles shown and have most recently clicked, or double-clicked on the map itself.

Now, keep in mind that the only thing that this lengthy code is doing is copying and pasting the URL from Google Maps, which is just as easy for the user to do and using a Button to do it. But, this methodology could be used for some other features in your projects.

(Try to) Enjoy.

Hope this hepps!
Jul 11 '18 #2

Expert 100+
P: 1,427

If it's any help, if you left click twice on Google Maps, you get a pushpin and box with an address with lat & long.

If you right click on the box, and choose "inspect" you get a page of HTML that can be read to give the Lat & Long and address.

I have a very complex routine that can read a web page of share prices, and this may well adapt to read these values.

Jul 11 '18 #3

P: 32
Thanks gentlemen as always. After I set the pushpin, then press the command button, I am not able to see where - if anywhere - the lat & lng of the pin was saved. Should there be somewhere in the code you posted to identify the table fields where these are to be stored?
Jul 12 '18 #4

Expert Mod 5K+
P: 5,285
The code that twinnyfo posted is not saving the information at all instead it's sending it to the immediate window at Line 20 Debug.Print strTemp press <ctrl><g> to open the VBA editor and the immediate window - now go back the main Access interface (leave the VBE open), open your form, etc...
Once you click on the command button bring your VBE back to the front and you will see the string that twinnyfo mentions below his code block.

Also take note that he states that the Lat/Long is not being pulled using this code; instead, the url related to the map view is being pulled.

Mminieri, normally we don't provide full code or application development; however, a quick search of the internet found this: http://www.alfainfo.it/gps-latitude-...rosoft-access/ I believe that this is somewhat close to what it is that you are attempting to do so it may be a good starting point for use to work with - It's not exact but maybe close.
Jul 12 '18 #5

Post your reply

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