This should give you some ideas:
(additions commented and marked with asterisks)
Code:
Private Sub Command0_Click()
.
.declarations were here
.
'**** add error handler ****
On Error GoTo ProcessError:
'************************
'Set up the application
Set objMap = objApp.ActiveMap
.
.set up stuff here
.
With rstmilage
.MoveFirst
Do While Not rstmilage.EOF
strfromzip = Nz(![fromzip])
strtozip = Nz(![tozip])
.
. route stuff
.
rstmilage.Edit
rstmilage("MPZipDist") = objRoute.Directions.Item(m).ElapsedDistance
rstmilage("Create_Time") = CalcTime
'**** add label so error handler knows where to return ****
SKIP_TO_NEXT:
'*************************************************
objRoute.Clear
rstmilage.Update
rstmilage.MoveNext
objRoute.Clear
Else
.
. else stuff here
.
End If
Loop
rstmilage.Close
End With
objApp.Quit
MsgBox "All Done"
'*********************************
'*** Add subroutine exit so sub does not
'*** fall into error code
'*********************************
Exit_:
Exit Sub
'********************************
'*** code that handles the error
'********************************
ProcessError:
'if the error number is equal to that generated when
'connectors not available
If Err.Number = "-2147221503" Then
'mark recordset for editing
rstmilage.Edit
'set values
rstmilage("MPZipDist") = "999999"
rstmilage("Create_Time") = CalcTime
'go to label
Resume SKIP_TO_NEXT
Else
'otherwise show error and exit
MsgBox "ERROR: " & Err.Number & vbCrLf _
& Err.Description & vbCrLf _
& "Module: Module1" & vbCrLf _
& "Subroutine: TestRoute" & vbCrLf & vbCrLf _
& "Exiting Now"
GoTo Exit_
End If
End Sub