linbayzak
asked on
Calculating route using mappoint and microsoft access
Hi Experts,
I have come a long way with this program so far, but I am really stuck now. Here is the line of code that is throwing an error "method or data member not found"...
objroute.Waypoints.Add objMap.FindAddressResults( rs2("OrigA ddress1"), rs2("OrigCity"), rs2("OrigState"), rs2("OrigZip").Item(1))
The rest of the code is below. Help, please. Thanks.
Laura :-)
I have come a long way with this program so far, but I am really stuck now. Here is the line of code that is throwing an error "method or data member not found"...
objroute.Waypoints.Add objMap.FindAddressResults(
The rest of the code is below. Help, please. Thanks.
Laura :-)
Private Sub cmbRunPSIQuery_Click()
'On Error GoTo Err_cmbRunPSIQuery_Click
Dim rs As Recordset
Dim rs2 As DAO.Recordset
Dim stDocName As String
Dim oApp As MapPoint.Application
stDocName = "qryTripManifestforPrinttoFilePSIInvoice"
Set oApp = CreateObject("MapPoint.Application")
CurrentDb().Execute "DELETE * FROM tblMapquestMiles"
Set rs = CurrentDb.OpenRecordset("Select * From tblMapquestMiles")
Set rs2 = CurrentDb().OpenRecordset("Select * from qryTripManifestforPrinttoFilePSIInvoiceCopy Where VendorID = " & cboVendorID.Value & " and (TripDate >= #" & txtStartDate.Value & "# and TripDate <=#" & txtEndDate.Value & "#)", dbOpenSnapshot)
Stop
Do While Not rs2.EOF
Set objMap = oApp.NewMap
Set objroute = oApp.ActiveMap
'Add route stops and calculate the route
objroute.Waypoints.Add objMap.FindAddressResults(rs2("OrigAddress1"), rs2("OrigCity"), rs2("OrigState"), rs2("OrigZip").Item(1))
objroute.Waypoints.Add objMap.FindAddressResults(rs2("DestAddress1"), rs2("DestCity"), rs2("DestState"), rs2("DestZip").Item(1))
objroute.Calculate
rs.AddNew
rs("TripNumber") = rs2("TripNumber")
rs("RoundedMiles") = objroute.Distance
rs.Update
rs2.MoveNext
Loop
Set rs = Nothing
Set rs2 = Nothing
oApp.Quit
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_cmbRunPSIQuery_Click:
Exit Sub
Err_cmbRunPSIQuery_Click:
MsgBox Err.Description
Resume Exit_cmbRunPSIQuery_Click:
End Sub
... or: objMap
ASKER
No, I didn't declare them. My boss started this code out as a function. I'll try to declare them and see what happens. Thanks :-)
ASKER
Ok, I declared:
Dim objroute As MapPoint.Route
Dim objMap As MapPoint.Map
and I still get the same error...it always stops on .Item and is grayed out instead of highlighted yellow. Any ideas what is wrong? Thanks :-)
Laura
Dim objroute As MapPoint.Route
Dim objMap As MapPoint.Map
and I still get the same error...it always stops on .Item and is grayed out instead of highlighted yellow. Any ideas what is wrong? Thanks :-)
Laura
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Experts,
You were right, the object wasn't declared. Yes, Capricorn1, that line will work, part of the problem was that I had the closing parentheses at the end instead of after OrigZip and DestZip. At any rate, it is working. Thanks
Laura
You were right, the object wasn't declared. Yes, Capricorn1, that line will work, part of the problem was that I had the closing parentheses at the end instead of after OrigZip and DestZip. At any rate, it is working. Thanks
Laura
I can't see where you actually declared: objroute
For example:
Dim objroute as XXXX
JeffCoachman