Good morning everyone,
I have a bit of code that I have recycled on a few buttons that all work fine. However this one bit of code associated with this particular button I cannot seem to get to work properly. As I said I have used code nearly identical to this on other buttons that works just fine. I seem to be missing something very obvious but for the life of me I cannot seem to figure out the problem. Below is the code that I am having trouble with. Specifically the line
'Set MyRS = MyDB.OpenRecordSet(QryOrTblDef)'
The error that I get is-
Run-time error '3061':
Too few parameters. Expected 1.
Any help is greatly appreciated. Thank you all for having a look at this.
I have a bit of code that I have recycled on a few buttons that all work fine. However this one bit of code associated with this particular button I cannot seem to get to work properly. As I said I have used code nearly identical to this on other buttons that works just fine. I seem to be missing something very obvious but for the life of me I cannot seem to figure out the problem. Below is the code that I am having trouble with. Specifically the line
'Set MyRS = MyDB.OpenRecordSet(QryOrTblDef)'
Code:
Private Sub cmdPlotAllInCounty_Click()
'This creates a text file with a KML extension that Google Earth can read
'Created by Rex Morgan 6/1/2010 with help from World Access Forums
'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
Dim iFile As Integer
QryOrTblDef = "MyQuery"
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset(QryOrTblDef)
iFile = FreeFile
Open "//ggw-s-win/home/rex.morgan/My Documents/KML help/QryKmlcboCounty.kml" For Output Shared As #iFile
Print #iFile, "<?xml version=""1.0"" encoding=""UTF-8""?>"
Print #iFile, "<kml xmlns=""http://earth.google.com/kml/2.1"">"
Print #iFile, "<Document>"
Print #iFile, " <name>SpottersInCounty.kml</name>"
Print #iFile, " <Folder>"
Print #iFile, " <name>Spotters</name>"
Print #iFile, " <open>1</open>"
Print #iFile, " <description><![CDATA[]]></description>"
With MyRS
Do Until .EOF
Print #iFile, " <Placemark>"
strText = " <description><![CDATA[Name: " & MyRS.Fields(1) & " " & MyRS.Fields(2) & "<br>City: " & MyRS.Fields(6) & "]]></description>"
Print #iFile, strText
strText = " <name>" & MyRS.Fields(1) & " " & MyRS.Fields(2) & "</name>"
Print #iFile, strText
Print #iFile, "<Point>"
strText = "<coordinates>" & MyRS.Fields(20) & "," & MyRS.Fields(19) & "</coordinates>"
Print #iFile, strText
Print #iFile, " </Point>"
Print #iFile, " </Placemark>"
.MoveNext
Loop
End With
Print #iFile, " </Folder>"
'Print #iFile, " </Folder>"
Print #iFile, " </Document>"
Print #iFile, "</kml>"
Close #iFile
MyRS.Close
Set MyRS = Nothing
Set MyDB = Nothing
Call Shell("explorer.exe " & "z:\My Documents\KML help\QryKmlcboCounty.kml", vbNormalFocus)
End Sub
The error that I get is-
Run-time error '3061':
Too few parameters. Expected 1.
Any help is greatly appreciated. Thank you all for having a look at this.