Access 2007 forms with parameterized RecordSource

主宰稳场 提交于 2019-12-11 02:34:27

问题


I'm sure there's a simple solution to this, but it seems to elude me.

So I have a form with a RecordSource of SELECT * FROM Table1 WHERE id=[@id]. (Yes, I know SELECT * is evil; it's just an example). Obviously the default behavior of this form is that upon opening, an input dialog will prompt for the "[@id]" value. But what I would like to do is call this form from VBA and instead of having the input dialog pop up, go ahead and tell the form what [@id] is, so the dialog never pops up, and the form opens just as if [@id] where replaced by a value in the query. I've tried the following so far...

Form_MyForm.RecordSource = String.Replace(Form_Form1.RecordSource, "[@id]", 1)
DoCmd.OpenForm "MyForm"

...and...

Form_MyForm.txtId.Value = 1
DoCmd.OpenForm "MyForm"

...and...

DoCmd.OpenForm "MyForm", acNormal, , "[@id]=" & 1

...but none of them seem to have the desired effect. How do i do this?

Thanks ahead of time.


回答1:


See if it's easier to drop the WHERE clause from your query:

SELECT * FROM Table1;

Then use the optional WhereCondition parameter with Openform to indicate which id value you want:

DoCmd.OpenForm "MyForm", WhereCondition:="id = 1"


来源:https://stackoverflow.com/questions/3200470/access-2007-forms-with-parameterized-recordsource

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