Simple Query

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?
 
D

Douglas J. Steele

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?]
 
A

Arpan

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 -
 

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

Similar Threads


Top