Simple Query

  • Thread starter Thread starter Arpan
  • Start date Start date
A

Arpan

Assume that a MS-Access table has 3 columns - UID (AutoNumber), FName
(Text) & LName (Text).

When I run the following query in MS-Access

PARAMETERS UID Long;
SELECT UID, FName, LName
FROM tblUsers
WHERE UID=UID

Access first prompts me to enter a value for the input parameter 'UID'.
Irrespective of the value I I supply as the UID, Access should retrieve
only one row since UID is unique in the table but Access retrieves all
the records instead.

Where am I erring?
 
Parameter names need to be enclosed in square brackets:

PARAMETERS [UID] Long;
SELECT UID, FName, LName
FROM tblUsers
WHERE UID=[UID]

However, it's possible that Access will have problems with that, due to the
field name and the parameter name being the same. If that's the case, change
the name of the parameter:

PARAMETERS [UID?] Long;
SELECT UID, FName, LName
FROM tblUsers
WHERE UID=[UID?]
 
Thanks Douglas for the corrections :-)

Parameter names need to be enclosed in square brackets:

PARAMETERS [UID] Long;
SELECT UID, FName, LName
FROM tblUsers
WHERE UID=[UID]

However, it's possible that Access will have problems with that, due to the
field name and the parameter name being the same. If that's the case, change
the name of the parameter:

PARAMETERS [UID?] Long;
SELECT UID, FName, LName
FROM tblUsers
WHERE UID=[UID?]

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)



Assume that a MS-Access table has 3 columns - UID (AutoNumber), FName
(Text) & LName (Text).
When I run the following query in MS-Access
PARAMETERS UID Long;
SELECT UID, FName, LName
FROM tblUsers
WHERE UID=UID
Access first prompts me to enter a value for the input parameter 'UID'.
Irrespective of the value I I supply as the UID, Access should retrieve
only one row since UID is unique in the table but Access retrieves all
the records instead.
Where am I erring?- Hide quoted text -- Show quoted text -
 
Back
Top