0
votes

Im building a button to open googlemaps with waypoints marked of all the points in my subform. On click however I keep getting Run-time error '3061':
Too few parameters. Expected 1

code below

    Private Sub Route_Plan_Click()
Dim strHyperlink As String
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("export_query")
    strHyperlink = "https://www.google.com/maps/dir/?api=1&origin=','start point address>,+'<start postcode>'"
 If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst
    Do Until rs.EOF = True
    strHyperlink = strHyperlink & "&waypoints=" & i & "='" & rs!Address & "',+'" & rs!Postcode & "'"
        rs.MoveNext
    Loop
 End If
Application.FollowHyperlink (strHyperlink)
MsgBox "Finished looping through records."
rs.Close
Set rs = Nothing
End Sub

the form sets a query record source which I am looping through to create the string for the weblink but am at a loss on why I am getting this error if anyone has any advice or suggestions it would be greatly appreciated.

2
At which line are you getting the error? If it's the line starting with Set rs, your query probably needs parameters you aren't providing, and you will need to either adjust your query or provide the required parameter.Erik A
Is your rs!Address and rs!PostalCode is received in excel?nishit dey
you are correct it is at the SET rsuser681413

2 Answers

0
votes

Open the query export_query directly in Access, it will request missing data and you will be able to determine where is the problem. Usually parameter request appears when query contains wrong column names.

0
votes

Managed to solve it thanks to this thread VBA OpenRecordset Produces Error 3061

Added this into it code

Dim prm As DAO.Parameter 
Dim qdf As DAO.QueryDef 

export_query = "Select export_query.address, export_query.postcode from export_query" 
Set qdf = CurrentDb.CreateQueryDef(vbNullString, export_query) 
For Each prm In qdf.Parameters 
    prm.Value = Eval(prm.Name) 
Next 
Set rs = qdf.OpenRecordset