我尝试使用表CITIES中的城市更新表STATES中的州首府。 我想要两者,州名和城市名称都要参数化。
拥有此代码
UPDATE STATES
SET State_capital=DLookUp("ID","CITIES","City='Los Angeles'")
WHERE State_name=[Enter State Name:];
问题是城市名称未在DLookUp中参数化,Access不接受此更新形式:
UPDATE STATES
SET State_capital=(SELECT ID FROM CITIES WHERE City=[Insert city here])
WHERE State_name=[Enter State Name:];
解决方案是什么?谢谢!
答案 0 :(得分:3)
此查询适用于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:]