nepotist
11-03-2008, 08:33 AM
Hello Can some one explain me the following code.
I found this code in my search to find a way to relate access and google earth.
I want to add google earth feature to my existing database. I would create two more filed in my table one being latitude and the other longitude. as each record would be having its own values and I want the user to be able to view the aerial just by clicking a button.
Google earth uses a script called KML(Key Hole Markup language), which can be written in a notepad and save it a kml file, double clicking the file would take you the location directly. the actual code that for this is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Simple placemark</name>
<description>Attached to the ground. Intelligently places itself
at the height of the underlying terrain.</description>
<Point>
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
</Point>
</Placemark>
</kml>
so Once I click the button I need to open a note pad, type in the above code(whose latitude and logitude vary with each record), and my search lead to me the following code. Can some one explain to me what each step does.
Option Compare Database
Private Sub Command33_Click()
DoCmd.OpenQuery "ENTERYOURQRYORTABLEHERE"
'Export data to text file
Dim MyDB As Database
Dim MyRS As Recordset
Dim fld As Field
Dim strText As String
Dim MyTableName As String
Dim QryOrTblDef As String
QryOrTblDef = "ENTERYOURQRYORTABLEHERE"
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset(QryOrTblDef)
Open "ENTERKMLFILENAME" 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>"
Print #1, " <name>tools.kml</name>"
Print #1, " <Folder>"
Print #1, " <name>Tools</name>"
Print #1, " <open>1</open>"
Print #1, " <Folder>"
Print #1, " <name>Tools</name>"
Print #1, " <open>1</open>"
Print #1, " <Snippet maxLines=""2"">Tools</Snippet>"
Print #1, " <description><![CDATA[]]></description>"
With MyRS
Do Until .EOF
Print #1, " <Placemark>"
'Print #1, " <Point>"
strText = " <description><![CDATA[" & MyRS.Fields(3) & "<br><br>" & MyRS.Fields(4) &
"]]></description>"
Print #1, strText
strText = " <address> " & MyRS.Fields(0) & "</address>"
Print #1, strText
strText = " <name>" & MyRS.Fields(1) & "</name>"
Print #1, strText
'Print #1, " <Snippet maxLines="; 2; "></Snippet>"
'Print #1, " <description><![CDATA[]]></description>"
'Print #1, " <LookAt>"
'Print #1, " </LookAt>"
'Print #1, " </Point>"
Print #1, " </Placemark>"
.MoveNext
Loop
End With
Print #1, " </Folder>"
Print #1, " </Folder>"
Print #1, " </Document>"
Print #1, "</kml>"
Close #1
MyRS.Close
Set MyRS = Nothing
Set MyDB = Nothing
'Shell "ENTERKMLFILENAMEHERE"
End Sub
One more question:
Does anyone know if there is a way in which I could embed Google earth with in the form(like using plugin or some other way)
Thank you for you help
I found this code in my search to find a way to relate access and google earth.
I want to add google earth feature to my existing database. I would create two more filed in my table one being latitude and the other longitude. as each record would be having its own values and I want the user to be able to view the aerial just by clicking a button.
Google earth uses a script called KML(Key Hole Markup language), which can be written in a notepad and save it a kml file, double clicking the file would take you the location directly. the actual code that for this is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Simple placemark</name>
<description>Attached to the ground. Intelligently places itself
at the height of the underlying terrain.</description>
<Point>
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
</Point>
</Placemark>
</kml>
so Once I click the button I need to open a note pad, type in the above code(whose latitude and logitude vary with each record), and my search lead to me the following code. Can some one explain to me what each step does.
Option Compare Database
Private Sub Command33_Click()
DoCmd.OpenQuery "ENTERYOURQRYORTABLEHERE"
'Export data to text file
Dim MyDB As Database
Dim MyRS As Recordset
Dim fld As Field
Dim strText As String
Dim MyTableName As String
Dim QryOrTblDef As String
QryOrTblDef = "ENTERYOURQRYORTABLEHERE"
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset(QryOrTblDef)
Open "ENTERKMLFILENAME" 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>"
Print #1, " <name>tools.kml</name>"
Print #1, " <Folder>"
Print #1, " <name>Tools</name>"
Print #1, " <open>1</open>"
Print #1, " <Folder>"
Print #1, " <name>Tools</name>"
Print #1, " <open>1</open>"
Print #1, " <Snippet maxLines=""2"">Tools</Snippet>"
Print #1, " <description><![CDATA[]]></description>"
With MyRS
Do Until .EOF
Print #1, " <Placemark>"
'Print #1, " <Point>"
strText = " <description><![CDATA[" & MyRS.Fields(3) & "<br><br>" & MyRS.Fields(4) &
"]]></description>"
Print #1, strText
strText = " <address> " & MyRS.Fields(0) & "</address>"
Print #1, strText
strText = " <name>" & MyRS.Fields(1) & "</name>"
Print #1, strText
'Print #1, " <Snippet maxLines="; 2; "></Snippet>"
'Print #1, " <description><![CDATA[]]></description>"
'Print #1, " <LookAt>"
'Print #1, " </LookAt>"
'Print #1, " </Point>"
Print #1, " </Placemark>"
.MoveNext
Loop
End With
Print #1, " </Folder>"
Print #1, " </Folder>"
Print #1, " </Document>"
Print #1, "</kml>"
Close #1
MyRS.Close
Set MyRS = Nothing
Set MyDB = Nothing
'Shell "ENTERKMLFILENAMEHERE"
End Sub
One more question:
Does anyone know if there is a way in which I could embed Google earth with in the form(like using plugin or some other way)
Thank you for you help