2

I'm trying to update the state capital from table STATES with a city from table CITIES. I want both , the state name and city name to be parameterized.

have this code

UPDATE STATES
SET State_capital=DLookUp("ID","CITIES","City='Los Angeles'")
WHERE State_name=[Enter State Name:];

The problem is that the City name is not parameterized in DLookUp and Access does not accept this form of the update :

UPDATE STATES
SET State_capital=(SELECT ID FROM CITIES WHERE City=[Insert city here])
WHERE State_name=[Enter State Name:];

What is the solution?Thank you !

1

1 Answer 1

3

This query works for me in Access 2010:

PARAMETERS [Enter City name:] Text(255), [Enter State name:] Text(255);
UPDATE STATES SET 
State_capital=DLookup("ID","CITIES","City='" & Replace([Enter City name:],"'","''") & "'")
WHERE State_name=[Enter State name:]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.