使用变量作为表名 [英] Using Variables as Table Names
问题描述
我想知道是否有人知道如何在MS Access的SQL查询中使用变量作为表名。我的数据库根据合同号创建一个表(以合同号命名),我希望能够根据表单上的合同号从表中检索信息。
contract_no是表单上的下拉框。它也是表的名称。
到目前为止我已经得到了这段代码,
SELECT Document_corr2.EE_Ref_no AS [EE Ref# ],Document_corr2.Trim_Ref_no AS [Trim Ref#],Document_corr2.Subject,Document_corr2.Correspondence_from AS [Correspondence]
FROM [contract_no]
ORDER BY Document_corr2.EE_Ref_no;
我不知道如何使用FROM子句将下拉框值作为表名。
感谢您的帮助
你在错误的(MySQL)论坛。我会重定向它。
Ronald:很酷:
我想知道是否有人知道如何在MS Access的SQL查询中使用变量作为表名。我的数据库根据合同号创建一个表(以合同号命名),我希望能够根据表单上的合同号从表中检索信息。
contract_no是表单上的下拉框。它也是表的名称。
到目前为止我已经得到了这段代码,
SELECT Document_corr2.EE_Ref_no AS [EE Ref# ],Document_corr2.Trim_Ref_no AS [Trim Ref#],Document_corr2.Subject,Document_corr2.Correspondence_from AS [Correspondence]
FROM [contract_no]
ORDER BY Document_corr2.EE_Ref_no;
我不知道如何使用FROM子句将下拉框值作为表名。
感谢您的帮助
你需要做的是在代码中建立SQL字符串。
假设你有一个变量调用cmbTabName。
展开 | 选择 | 换行 | 行号
< blockquote>哦好的 - 我以为我可能不得不这样做。
这看起来像是一个愚蠢的问题,但用于显示结果的Listbox是基于一个查询 - 怎么做你得到列表框来显示VBA代码的数据?我只是运行编码SQL并将结果分配给列表框吗?我有意义吗?
对不起 - 我是工程师 - 不是程序员
提前致谢
Hi,
I was wondering if anyone has any idea how to use a variable as a table name in an SQL query in MS Access. My database creates a table based on a contract number (named after the contract number) and I wish to be able to retrieve info from a table based on the contract number on the form.
contract_no is a dropdown box on the form. It is the name of the table also.
I have gotten this code so far,
SELECT Document_corr2.EE_Ref_no AS [EE Ref#], Document_corr2.Trim_Ref_no AS [Trim Ref#], Document_corr2.Subject, Document_corr2.Correspondence_from AS [Correspondence]
FROM [contract_no]
ORDER BY Document_corr2.EE_Ref_no;
I don''t know how to use the FROM clause to take the dropdown box value as the table name.
thanks for your help解决方案You are in the wrong (MySQL) forum. I''ll redirect it.
Ronald :cool:
Hi,
I was wondering if anyone has any idea how to use a variable as a table name in an SQL query in MS Access. My database creates a table based on a contract number (named after the contract number) and I wish to be able to retrieve info from a table based on the contract number on the form.
contract_no is a dropdown box on the form. It is the name of the table also.
I have gotten this code so far,
SELECT Document_corr2.EE_Ref_no AS [EE Ref#], Document_corr2.Trim_Ref_no AS [Trim Ref#], Document_corr2.Subject, Document_corr2.Correspondence_from AS [Correspondence]
FROM [contract_no]
ORDER BY Document_corr2.EE_Ref_no;
I don''t know how to use the FROM clause to take the dropdown box value as the table name.
thanks for your helpWhat you need to do is build up the SQL string in code.
Say you have a variable call cmbTabName.
Expand|Select|Wrap|Line Numbers
Oh ok - I thought I may have to do that.
This may seem like a stupid question, but the Listbox used to display the results is based on a query - how do you get the listbox to display data from VBA code? Do I just run the coded SQL and assign the result to the listbox? Am I making sense?
Sorry - I am an engineer - not a programmer
Thanks in advance
这篇关于使用变量作为表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文