A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How do I change table name in Query through Form?



 
 
Thread Tools Display Modes
  #1  
Old August 21st, 2008, 11:47 PM posted to microsoft.public.access.forms
Francesco
external usenet poster
 
Posts: 18
Default How do I change table name in Query through Form?

My environment:
Query1 (source table changes every week - same structure-, SQL does not
change).
Report1 (source record always Query1).
Currently, I am manually replacing the table name in Query1, SQL view and
then my users can run Report1.
Is there a way to create a Form, so my users can just type in the new table
name, replacing the previous table in Query1?
After doing that, then users will have a "Print Report1" button with the
updated Query1.
Thank you very much for your help.
  #2  
Old August 22nd, 2008, 12:01 AM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default How do I change table name in Query through Form?

You can try something like:

Dim qdfCurr As DAO.QueryDef
Dim strSQL As String

Set qdfCurr = CurrentDb.QueryDefs("Query1")
strSQL = qdfCurr.SQL
strSQL = Replace(strSQL, "OldTableName", "NewTableName")
qdfCurr = strSQL
qdfCurr.Close
Set qdfCurr = Nothing

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"francesco" wrote in message
news
My environment:
Query1 (source table changes every week - same structure-, SQL does not
change).
Report1 (source record always Query1).
Currently, I am manually replacing the table name in Query1, SQL view and
then my users can run Report1.
Is there a way to create a Form, so my users can just type in the new
table
name, replacing the previous table in Query1?
After doing that, then users will have a "Print Report1" button with the
updated Query1.
Thank you very much for your help.



  #3  
Old August 22nd, 2008, 01:17 AM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default How do I change table name in Query through Form?

The question that begs asking is why does the table change weekly?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200808/1

  #4  
Old August 22nd, 2008, 08:15 PM posted to microsoft.public.access.forms
Francesco
external usenet poster
 
Posts: 18
Default How do I change table name in Query through Form?

Doug,
Thank you very much for the code provided. This, however, doesn't do what
I'm looking for.
I just had a thought to accomplish my goal via a different approach.
(All tables always have the same structure, but different data).
I create a new "master" table, Table1.
Query1 will always have as source record Table1, so Query1 and Report1 will
remain untouched.
Create a form with a dropdown.
Every time a new table is created, it will be automatically added to the
dropdown.
Selecting a table (ex: tblData1) from the dropdown, data from tblData1 will
be copied to master Table1.
Users will just press the Print Report1 button.
Upon closing Report1, data from master Table1 will be deleted.
Easy for me to say, but how do I implement it?

Thank you very much for your time.



"Douglas J. Steele" wrote:

You can try something like:

Dim qdfCurr As DAO.QueryDef
Dim strSQL As String

Set qdfCurr = CurrentDb.QueryDefs("Query1")
strSQL = qdfCurr.SQL
strSQL = Replace(strSQL, "OldTableName", "NewTableName")
qdfCurr = strSQL
qdfCurr.Close
Set qdfCurr = Nothing

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"francesco" wrote in message
news
My environment:
Query1 (source table changes every week - same structure-, SQL does not
change).
Report1 (source record always Query1).
Currently, I am manually replacing the table name in Query1, SQL view and
then my users can run Report1.
Is there a way to create a Form, so my users can just type in the new
table
name, replacing the previous table in Query1?
After doing that, then users will have a "Print Report1" button with the
updated Query1.
Thank you very much for your help.




  #5  
Old August 22nd, 2008, 08:28 PM posted to microsoft.public.access.forms
Francesco
external usenet poster
 
Posts: 18
Default How do I change table name in Query through Form?

New data from different sources, new table. Must keep existing tables; may
not overwrite them.
If you have suggestions or a better solution, I would greatly appreciate it.

Thank you for your time.

Francesco


"Linq Adams via AccessMonster.com" wrote:

The question that begs asking is why does the table change weekly?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200808/1


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:41 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.