Auto generate query from form

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

Hi folks,

I need to create the following query for ten tables
daily. The only change is the table name. Is there a
way I can just input the table name on a form, then I
click on a button to generate the query?

SELECT Table2.Field1, Table2.Field2, Table2.Field3
FROM Table2;

Any help will be appreciated.

Thanks.

Tim.
 
Instead of using Table2 in your Select, use

"SELECT " & Me.txtbox.value & ".Field1, " &
Me.txtbox.value & ".Field2 ---etc
"From " & Me.txtbox.Value

Hope that helps.
 
David,

Thanks for your suggestion. The method you mentioned
cannot create a query. It only can run a query with
specified table name. I need something can use the table
name I provided and then create a query for me.

Thanks.

Tim.
 
Try the
Application.CurrentDb.CreateQueryDef
method.

ex.
Application.CurrentDb.CreateQueryDef "CreatedQueryName" "SELECT * From " &
myTableName
 
Back
Top