【发布时间】:2015-04-12 15:43:06
【问题描述】:
我正在 Access 中创建一个程序,它将带有坐标的表格导出到可查看的 KML 文件中。目前我使用的代码从记录集的开头开始,并将每条记录单独打印到 KML 文件中。
但是,我希望代码将记录组织到 KML 文件上的文件夹中(基于它们创建的周数)。我能找到将文件夹编码到 KML 文件中的唯一方法是,我需要将条目嵌套到代码的特定部分中。由于我是从上到下写我的记录,而且它们不是我希望它们排序的顺序,所以会导致问题。
我对 VBA 很陌生,我想解决这个问题的唯一方法是多次通过我的记录集,每次检查不同的一周,这样我就可以把它写到正确的位置在 KML 文件中。虽然数据库相当大,但我觉得应该有一种更简单或更清洁的方法来做到这一点。
感谢任何帮助或建议。 我当前的代码(只是写入 KML 的部分)
Open strSavePath For Output Shared As #1
'init KML file
Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>"
Print #1, "<kml xmlns=""http://www.opengis.net/kml/2.2"">"
Print #1, "<Document>"
'create plot styles
Print #1, "<Style id=""K1res"">"
Print #1, "<IconStyle> <color>ff14F0FF</color> <Icon><href>http://maps.google.com/mapfiles/kml/pal4/icon57.png</href></Icon></IconStyle>"
Print #1, "</Style>"
Print #1, "<Style id=""K1com"">"
Print #1, "<IconStyle> <color>FF1473FF</color> <Icon><href>http://maps.google.com/mapfiles/kml/pal4/icon57.png</href></Icon></IconStyle>"
Print #1, "</Style>"
With MyRS
Do Until .EOF
Print #1, " <Placemark>"
If Me.boxPlotTitle.Value = True Then
Print #1, " <name>" & DateShort(MyRS.Fields(4)) & "</name>"
End If
Print #1, " <description>" & CleanupStr(MyRS.Fields(8)) & vbNewLine & vbNewLine & "Date: " & MyRS.Fields(4) & "</description>"
If MyRS.Fields(6) = "Residential" Then
Print #1, " <styleUrl>#K1res</styleUrl> "
Else
Print #1, " <styleUrl>#K1com</styleUrl> "
End If
Print #1, " <Point>"
strText = " <coordinates>" & MyRS.Fields(11) & "," & MyRS.Fields(10) & "</coordinates>"
Print #1, strText
Print #1, " </Point>"
Print #1, " </Placemark>"
.MoveNext
Loop
End With
Print #1, "</Document>"
Print #1, "</kml>"
Egress:
On Error Resume Next
Close #1
MyRS.Close
Set MyRS = Nothing
Set MyDB = Nothing
MsgBox "Successfully Exported KML"
Call Shell("explorer.exe " & strSavePath, vbNormalFocus)
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume Egress
End Sub
【问题讨论】:
-
你为什么不设计你的查询来把记录集按你想要的顺序排列?
-
我应该澄清一下,最终我将向此 KML 文件添加多个记录集,并且我不知道有一种方法可以打开两个表并将它们过滤到同一个记录集中并将它们排序在一起。
标签: xml vba ms-access directory kml