Recordset Error (1 Viewer)

Jord

Registered User.
Local time
Today, 18:45
Joined
Apr 24, 2012
Messages
17
Hi,

I'm pretty new to Access & vba so thanks in advance.

I have written the following code but get Run-time error '3061': Too few parameters. Expected 1.

Code:
Private Sub Command257_Click()

Dim dbsMyMap As DAO.Database
Dim rstPositions As DAO.Recordset
Dim strURLBeg As String
Dim strURLEnd As String
Dim strMyURL As String
Dim strURL As String
Set dbsMyMap = CurrentDb()
Set rstPositions = dbsMyMap.OpenRecordset("Top10 Closest")

If rstPositions.EOF Then Exit Sub

strMyURL = ""

With rstPositions
    Do Until .EOF
    MyLat = rstPositions![CUSTLAT]
    MyLong = rstPositions![CUSTLONG]
    strMyURL = strMyURL & "+to:" & MyLat & "," & MyLong
    .MoveNext
    Loop
End With


strURLBeg = "http://maps.google.co.uk/maps?saddr="
strURLEnd = "&t=m&doflg=ptk"

strURL = URLBeg & MyURL & URLEnd

Debug.Print "URL would be: " & strURL

dbsMyMap.Close
rstPositions.Close

Set dbsMyMap = Nothing
Set rstPositions = Nothing

End Sub

The "Top 10 Closest" is a query within the database.
Hope I made sense, thanks for any help.

Jord
 

Jord

Registered User.
Local time
Today, 18:45
Joined
Apr 24, 2012
Messages
17
Ok I have changed the code a little and it works if I change the ("Top10 Closest") to ("Customers") which is a table rather than a Query.
Any ideas?

Code:
Private Sub Command257_Click()

Dim dbsMyMap As DAO.Database
Dim rstPositions As DAO.Recordset
Dim strURLBeg As String
Dim strURLEnd As String
Dim strMyURL As String
Dim strURL As String
Set dbsMyMap = CurrentDb()
Set rstPositions = dbsMyMap.OpenRecordset("Top10 Closest")

If rstPositions.EOF Then Exit Sub

strMyURL = ""

With rstPositions
    Do Until .EOF
    MyLat = rstPositions![CUSTLAT]
    MyLong = rstPositions![CUSTLONG]
    strMyURL = strMyURL & "+to:" & MyLat & "," & MyLong
    .MoveNext
    Loop
End With


strURLBeg = "http://maps.google.co.uk/maps?saddr="
strURLEnd = "&t=m&doflg=ptk"

strURL = strURLBeg & strMyURL & strURLEnd

MsgBox "URL would be: " & strURL

rstPositions.Close
dbsMyMap.Close

Set dbsMyMap = Nothing
Set rstPositions = Nothing

End Sub
 

boblarson

Smeghead
Local time
Today, 10:45
Joined
Jan 12, 2001
Messages
32,059
Did your query have any criteria on it which referenced a form/control?
 

Users who are viewing this thread

Top Bottom