开发者

Access VBA: Set record source of form on button click

I have a "View Report" button in o开发者_如何转开发ne form and when the button is clicked I want to change the record source of another form to something else and refresh it?

I tried to put this code in the click function of the button but its not working

    access.forms("Form1").RecordSource = {bla bla}

but its not working. The error says it can find Form1..

Any help is appreciated!

Thank you!


The Access.Forms collection is a collection of the open forms only. If you want to set the RecordSource of another form, you must ensure the other form is open first.

If you want, you can open the other form as Hidden, set the RecordSource, and then set the form's Visible property to True.


You don't have to open the other form as hidden, You can simply open your form when you really need and then set the Recordsource

DoCmd.OpenForm "Form1"
Forms.Item("Form1").RecordSource = {bla bla}


This is old problem, just encoutered it though. I threw up a screen scrape as form showing, set the originial form recordset to nothing closed the form, deleted everything from my temp table, then reopened the form. Worked fine. Just beware of what cycles if you have any oncurrent events, I had to use a boolean to cancel oncurrent when this action was occuring.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜