excluding certain field value from recordset output

E

efandango

I need to exclude any Postcode which has the Value "X" from the resultant
recordset output by the code below:

I want to say, if any postcodes field contains the single value of 'X', then
don't include it in the output data: How do I add this optional clause?

The Code:
***************
'Assume lngRunNo is either declared elsewhere or passed as an argument
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sRoute As String
Dim iWPCount As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("Select [Run_waypoint], [Postcode] from
tbl_Run_Reveal_Target where [Run_No]=" & Me.Run_No & " order by [OrderSeq];",
dbOpenForwardOnly)

Do Until rs.EOF
iWPCount = iWPCount + 1
sRoute = sRoute & IIf(iWPCount = 1, "from: ", " to: ") &
rs![Run_waypoint] & ", " & "London, " & rs![Postcode]
rs.MoveNext
Loop
rs.Close

If iWPCount >= 2 Then

Parent.Form.Run_Test_WebBrowser.Navigate
"http://maps.google.co.uk/maps?f=q&hl=en&q=" & sRoute

Else
MsgBox "Run must have at least two waypoints"
End If
End Sub

***************
 
R

Ron2006

expand your where clause to be something like this....

where [Run_No]=" & Me.Run_No & " and [Postcode] <> "X" order by
[OrderSeq];"
 
E

efandango

I tried this:

Set rs = db.OpenRecordset("Select [Run_waypoint], [Postcode] from
tbl_Run_Reveal_Target where [Run_No]=" & Me.Run_No & " and Postcode]<> "X"
order by [OrderSeq];", dbOpenForwardOnly)


but access threw an error: expected list separator or )

any idea where and what character i should correct this with?
 
E

efandango

Ron,

thanks for your help, after getting the error message (see previous post), I
did some hunting around for syntax usage for text and tried this: (using the
' instead of ") and all worked.


Set rs = db.OpenRecordset("Select [Run_waypoint], [Postcode] from
tbl_Run_Reveal_Target where [Run_No]=" & Me.Run_No & " and [Postcode]<> 'X'
order by [OrderSeq];", dbOpenForwardOnly)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top