Select Where Two Condiotions as met

  • Thread starter Johnkl via AccessMonster.com
  • Start date
J

Johnkl via AccessMonster.com

Can anyone point the correct syntax ??


Set rstW = db.OpenRecordset ((("Select OrderID,FileID From tblOrders " & _
"(Where OrderID = " & lngOrder) And (FileID = " & lngFile)"

Kind regards
John
 
B

BeWyched

Try:

Set rstW = db.OpenRecordset ("Select OrderID, FileID From tblOrders " & _
"Where (OrderID = " & lngOrder & " And FileID = " & lngFile & ")")

This assumes OrderID and lngFile are integers. If they are strings then try:

Set rstW = db.OpenRecordset ("Select OrderID, FileID From tblOrders " & _
"Where (OrderID = '" & lngOrder & "' And FileID = '" & lngFile &
"')")

where, exagerated, '" and "' are ' " and " ' (miss out the appropriate '"
and "' if one or other is an integer and t'other a string)

Cheers.

BW
 
D

DaveT

Here's the actual SQL from query design (Access 2007) on table using two long
int fields. Note that the SQL statement ends with semi-colon.

SELECT tTestRequest.TestID, tTestRequest.RequesterID
FROM tTestRequest
WHERE (((tTestRequest.TestID)=21) AND ((tTestRequest.RequesterID)=159));
 
D

Douglas J. Steele

The semi-colon is completely optional in Access.

The problem with the original statement was the placement of quotes (plus
some wonky parentheses). It needs to be

Set rstW = db.OpenRecordset ("Select OrderID,FileID From tblOrders " & _
"Where (OrderID = " & lngOrder & ") And (FileID = " & lngFile & ")"
 
B

BeWyched

Hi Douglas

I believe your line needs a closing )

i.e.

Set rstW = db.OpenRecordset ("Select OrderID,FileID From tblOrders " & _
"Where (OrderID = " & lngOrder & ") And (FileID = " & lngFile & ")")

BW
 
Top