I have a couple of different forms. On one form I have cmd button linked to the following code.
That code works fine. However when I try to reuse the code (on a different form with a different query) with a few changes I get the following error.
Run-Time error '3061':
Too few parameters. Expected 2.
When I select debug the line highlighted is the Set MyRS= MyDB.OpenRecordset (QryOrTblDef)
Don't know what is going on here. Any help is greatly appreciated.
Code:
Private Sub Command5_Click()
'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 = "DanielsKMLtest"
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset(QryOrTblDef)
iFile = FreeFile
Open "//ggw-s-win/home/rex.morgan/My Documents/KML help/KMLTest.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>KMLTest.kml</name>"
Print #iFile, " <Folder>"
Print #iFile, " <name>Spotters</name>"
Print #iFile, " <open>1</open>"
Print #iFile, " <Folder>"
Print #iFile, " <name>Daniels County</name>"
Print #iFile, " <open>1</open>"
'Print #iFile, " <Snippet maxLines=""2"">Whatever</Snippet>"
Print #iFile, " <description><![CDATA[]]></description>"
With MyRS
Do Until .EOF
Print #iFile, " <Placemark>"
strText = " <description><![CDATA[Name: " & MyRS.Fields(0) & "<br>City: " & MyRS.Fields(1) & "<br>Phone: " & MyRS.Fields(3) & "]]></description>"
Print #iFile, strText
strText = " <name>" & MyRS.Fields(0) & "</name>"
Print #iFile, strText
Print #iFile, "<Point>"
strText = "<coordinates>" & MyRS.Fields(4) & "</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\KMLTest.kml", vbNormalFocus)
End Sub
That code works fine. However when I try to reuse the code (on a different form with a different query) with a few changes I get the following error.
Run-Time error '3061':
Too few parameters. Expected 2.
When I select debug the line highlighted is the Set MyRS= MyDB.OpenRecordset (QryOrTblDef)
Don't know what is going on here. Any help is greatly appreciated.