Why can't I specify criteria for a conditional query as a form component?

前提是你 提交于 2019-12-11 06:33:01

问题


I have two drop downs, Combo_A and Combo_B. I'm attempting to achieve a "cascading combo box" or "synchronous combo box" where a selection from Combo A (say, a US State) would populate Combo B (say a particular list of cities which belong to said state).

I understand using the VBA code to do this, and the reason you'd prefer to use VBA, but my question is WHY must I use VBA.

Simply making a conditional query with criteria of:

[Forms]![Main_Form]![State_Dropdown]

Doesn't seem to work. There IS a requery (of the City_Dropdown) performed AfterUpdate (of the State_Dropdown). Then I'm asked to provide the values for

Form!Main_Form!State_Dropdown

...after manipulating the State_Dropdown.

Why doesn't this work intuitively? Security? Function?


回答1:


Assuming the controls are on same form, don't need to reference the Forms collection and form name. In ComboB RowSource:
SELECT [City] FROM [Cities] WHERE [State]=[ComboA];

I recommend the requery code be in ComboB GotFocus event.

Be aware cascading comboboxes don't work nice with continuous or datasheet form if ComboB RowSource includes lookup alias.



来源:https://stackoverflow.com/questions/43220213/why-cant-i-specify-criteria-for-a-conditional-query-as-a-form-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!