VBA问题 - 创建在其列名中包含点的链接表 [英] VBA problem - create link table that has dot in its column name

查看:81
本文介绍了VBA问题 - 创建在其列名中包含点的链接表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我写了一个VBA代码,用于从SQL服务器创建ODBC链接表。代码只适用于SQL Server数据库中存在的大多数表。


但是,其中一个表的列名有一个点(例如[Payment Freq.New]),结果无法创建链接表。下面是创建链接表的代码,是否有任何解决方案将点作为列名称的一部分包含在内?谢谢。

Hi, I wrote a VBA code to create ODBC link table from SQL server. The code just works fine to most table exist in the SQL server database.

However, one of the table''s column name has a dot (e.g. [Payment Freq. New]), which result unable to create link table. Below is the code that creates link tables, is there any solution to include the dot as part of the column name? Thanks.

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

推荐答案

你不知道你跑的时候会发生什么这段代码(除了它失败之外)。


我只能建议您尝试手动建立链接,看看你得到了什么结果。它可以通过用下划线或其他东西替换点来自动修复名称。否则,我们需要更多详细信息。
You don''t say what happens when you run this code (Other than simply that it fails).

I can only suggest you try to make the link manually and see what results you get. It may fix the name automatically by replacing the dot with an underscore or something. Otherwise, we need more details in the question.


当我运行代码时,它会将ODBC链接表填充到表列表中。但是,当我将代码运行到此特定表时,没有显示错误,并且链接表未填充到表列表中。我知道它涉及列名称中的点的原因是,我尝试创建一个传递查询来打开表,当我执行查询时它要求我输入此列的值。 Access程序本身可能将字段名称视为< table>。< field>而不是单个字段名称。


我需要一些时间来手动构建表,因为表结构本身很大。我可以编写一些读取表的列名的代码,所以我可以在VBA中用它构建表吗?
When I run the code, it will populate a ODBC link table into the table list. But when I run the code to this particular table, no error has shown, and the link table is not populate into the table list. The reason I know it involves with the dot within a column name, is I tried creating a pass-through query to open the table, when I execute the query it ask me to enter value to this column. The Access program itself might have reckon the field name as <table>.<field> instead of a single field name.

I''ll need some time to build the table manually for the try out, as the table structure itself is large. Can I program some code that read the column names of the table, so I can build the table with that in VBA?




首先我永远不会使用在一个字段名称中的一个点,就像我永远不会把我的头放在狮子的嘴里一样!但我认为这不是你的选择。如果你将[Square Brackets]放在一个字段名称周围,它允许你包含空格;我不知道它对其他角色的效果如何。


第二篇文章:如果您的表存在于SQL Server中,那么您可以生成一个脚本(来自SQL Server Management Studio)来创建表。右键单击Studio中的表,然后选择''Script Table as>创建''并给出一个文件名。


您必须修改此脚本才能粘贴到Access中,但至少所有的字段名称都将被包含并拼写(拼写? )正确。


我同意NeoPa的意见,我们需要更多关于你要做什么以及为什么要做的信息?首先,它听起来像你想要创建一个链接(所以你不需要该结构)。其次,你似乎想要创建一个本地表?

S7
Hi
First I would never use a dot in a field name, same as I would never put my head in a lion''s mouth! But I take it was not your choice. If you put [Square Brackets] around a fieldname it allows you to include spaces; I dont know how well it works for other characters.

Second Post: If your table exists in SQL Server then you can generate a script (from SQL Server Management Studio) to create the table. Right click on the table in Studio then select ''Script Table as > CREATE To'' and give a file name.

You will have to modify this script before you can paste into Access but at least all your field names will be included and spelt (spelled?) correctly.

I agree with NeoPa that we need more info on what you are trying to do and why? First, it sound like you want to create a link (so you dont need the structure). Second, you seem to be wanting to create a local table?
S7


这篇关于VBA问题 - 创建在其列名中包含点的链接表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆