PDA

View Full Version : How to open a KML File



nepotist
11-03-2008, 02:30 PM
Hi,
can some one guide me through to how to open a KML file though vba access code.
the location of the file is "C:\TEST.KML".
If i manually double click it it would open google earth and zoom in to a particular location.

I tired
the following

dim retval
retval = shell("c:\programfiles\google\googleearth.exe".1)

this one opens google earth but not the file i need. though my file and the above syntax open up google earth the difference is that my file open up and directly zooms in to the location of my interest.

I tried to use "c:\test.kml" but is does not recognise it
any clue??

Carl A
11-03-2008, 09:03 PM
Never worked with them personally but here is a link that may help.

http://www.access-programmers.co.uk/forums/showthread.php?t=151797&highlight=kml

Carl A
11-03-2008, 09:18 PM
Oops! I suppose I should have read your other post.

nepotist
11-04-2008, 06:03 AM
lol I was about to say that... Any one? how I can open it through VBA code??..:think: :ipray: :hairpull: :anyone: :dunno :banghead:

CreganTur
11-04-2008, 06:33 AM
Please post a sample KML file and if you still need help with the database portion of the code, then post a sample database as well, please, so we don't have to recreate everything you've already done.

jfournier
11-04-2008, 06:42 AM
If you're just trying to launch Google Earth through VBA you can just use the following:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As _
Long

Private Const SW_SHOW = 1
Public Sub Navigate(ByVal NavTo As String)
If NavTo = "" Then Exit Sub
Dim hBrowse As Long
hBrowse = ShellExecute(0&, "open", NavTo, "", "", SW_SHOW)
End Sub

Sub TryGE()
Navigate "C:\test.kml"
End Sub

All it does is calls the windows shell with the file path you want, and let windows take care of it, just like if you double clicked the file (close enough, anyway)

nepotist
11-04-2008, 07:10 AM
Well guys thank you all you interest ... it was actually a simple solution..... The
Followhyperlink command works perfectly fine...
FYI the solution to problem for this one and my previous post is as follows.

Private Sub cmdaerial_Click()


Dim db As Database
Dim rstAerial As Recordset
Dim fld As Field
Dim qry As String
Dim strtext As String
Dim id

id = Form_TMC_Dairy.Intersection_ID.Value
Set db = CurrentDb()

Set rstAerial = db.OpenRecordset("SELECT tblcmsintersections.globalID,tblcmsintersections.Latitude,tblcmsintersectio ns.Longitude FROM tblCMSIntersections WHERE (tblCMSIntersections.GlobalID = " & id & " );")
strtext = " <coordinates>" & rstAerial.Fields(1) & "," & rstAerial.Fields(2) & ",0</coordinates>"

Open "C:\KMLFile.kml" For Output Shared As #1

Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>"
Print #1, "<kml xmlns=""http://earth.google.com/kml/2.1"">"
Print #1, "<Document>"

With rstAerial
Do Until .EOF
Print #1, " <Placemark>"
Print #1, " <Point>"
strtext = " <coordinates>" & rstAerial.Fields(1) & "," & rstAerial.Fields(2) & "</coordinates>"
Print #1, strtext
Print #1, " </Point>"
Print #1, " </Placemark>"
.MoveNext
Loop
End With

Print #1, "</Document>"
Print #1, "</kml>"
Close #1
rstAerial.Close


Set rstAerial = Nothing
Set db = Nothing
FollowHyperlink ("C:\KMLFile.kml")

End Sub

Though I was able to get it to work I still dont get / understand this command line that initates a text file and prints the text
Open "C:\KMLFile.kml" For Output Shared As #1
It creates a textfile prints the data in it and saves it as a kml file.. but shared #1 i dont get that.