Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prompt For Table Name in Update Query?? 1

Status
Not open for further replies.

humbletechie

IS-IT--Management
May 3, 2001
33
0
0
US
Hi,

Is it possible to have an update query prompt for the table name that is being updated. I need to run an update query that will need to update different tables depending on what the user chooses. The tables all have the same field names.

Thanks in advance!
 
Hi,

I figured out how to do this. I just created 1 update query against 1 table. I then created a form that the user inputs a table name into. In the OnClick event on the update button, I used the rename command to rename the table the user specified in the form to the table name the update query is using. After the update query runs, I have another rename command that renames the table back.

Thanks
 
There is no way directly in a saved query to make the table name a parameter. However, you could create VBA coding to construct an SQL statement and make the table being updated a parameter.

For example, if you have a form that has a textbox where the user can enter the table name (or a combo box where the user can select the table name) you could add code behind the form to build a SQL string and run it:

DoCmd.RunSQL "UPDATE " & Me.TableName & " SET Field1 = Now();"

This example would update the selected table (Me.TableName) with the current date and time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top