Ok, so I'm trying to loop thru a query and pull out the data in the first field of the query. Then concatenate that data into a string to be used in Google Maps. The data represent addresses for stops on a trip. If I use a simple Select Query like "SELECT * FROM STOREtbl" - it works fine. But I want to only select certain records. I created a query that pulls the right information, but when I use that query SQL vs the simple one; I get an error. (Run-Time Error 3061... Too Few Parameters, Expected 1.) Here is my code.
Appreciate any help you can offer.
Jeff
Code:
Private Sub PRINTMAPlbl_Click()
Dim dbs As DAO.Database
Dim rsSQL As DAO.Recordset
Dim strSQL As String
Dim BUILDURL As String
BUILDURL = "[URL unfurl="true"]https://www.google.com/maps/dir/"[/URL]
Set dbs = CurrentDb
strSQL = "SELECT DISTINCT STOREtbl.STOREADDRESS, STOPtbl.STOPSUFFIX FROM TRIPtbl, STOREtbl INNER JOIN STOPtbl ON STOREtbl.STOREID = STOPtbl.STOREID WHERE (((TRIPtbl.TRIPID) = [Forms]![MAINfrm]![MAINSUBfrm]![TRIPbox].[Value]) And ((STOPtbl.TRIPID) = [Forms]![MAINfrm]![MAINSUBfrm]![TRIPbox].[Value])) ORDER BY STOPtbl.STOPSUFFIX;"
Set rsSQL = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
With rsSQL
rsSQL.MoveFirst
If Not (rsSQL.EOF) Then
Do Until rsSQL.EOF = True
BUILDURL = BUILDURL & Replace(rsSQL.Fields(0), " ", "+") & "/"
rsSQL.MoveNext
Loop
Else
MsgBox "There are no records in the recordset."
End If
End With
If Right(BUILDURL, 1) = "/" Then
BUILDURL = Left(BUILDURL, Len(BUILDURL) - 1)
End If
Application.FollowHyperlink BUILDURL
End Sub
Appreciate any help you can offer.
Jeff