我在Access中创建了一个程序,该程序可将坐标导出为可查看的KML文件。目前,我正在使用的代码从记录集的开始处开始,并将每条记录单独打印到KML文件中。VBA访问:将各种记录组织到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
为什么不用你的查询来按照你想要的顺序放置记录集? – geocodezip 2015-02-12 04:03:12
我应该澄清,最终我将为此KML文件添加多个记录集,并且我不知道如何打开并将两个表过滤到相同的记录集中并将它们排列在一起。 – 2015-02-12 23:48:04