Open query or table from a button

When I made a button in form to open form or report,
ThisDatabaseDocument.FormDocuments.getByName(“Form1”).open()
ThisDatabaseDocument.ReportDocuments.getByName(“Report1”).open()

But I can’t open query or table same way.
How can I do to open query or table from a button?

Hi

The simple solution is of course to base a form on the table/query…

It may nevertheless be directly open table/query as in the OpenTableQuery.odb attached.

I only use a single procedure for both: I test the name of the button to choose between the table and the query.

note: my source was here.

As Drew said not sure this is THE final answer - but it works

[EDIT]

If you want to open a query in design view to give parameters, my suggest is to use a form for parameters input, then update the query as in this FR.MACROS_Base_003_RapportParam.odb

Regards

Thanks very much. I tried that Drew’s source before but my skills and English is not enough, I failed. Now, I checked OpenTableQuery.odb, It worked.

But there’s just one more thing I need to know. I’d like to open query and type words in criterion each time, so is there any way to open query design view from a button?

That update-query method worked.
Thank you very much for your help.

Hi @PYS,
I tried running your file but when I click the report button on the form I get the error that the types don"t match in the code for the Macro.