如何使用VBA查明是否所有表都已连接? [英] How to use VBA to find out if all of the tables are connected?

查看:93
本文介绍了如何使用VBA查明是否所有表都已连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法找出BE中的所有表是否都已连接?我想在首次打开数据库时打开一个表单。在其On_Load事件中,我想检查是否所有表都已连接。如果是,则表单将关闭,主窗体将打开供用户使用数据库。如果表没有连接,那么我将使用启动表单输入要传递给我的ReLink函数的BE名称和文件路径(正在另一个线程中处理)。我只需要知道如何检查表是否已连接。我已经浏览了MSDN上的所有TableDef属性,但信息非常稀缺。我找不到任何说检查连接的东西,所以我猜这里没有任何明确的东西,但我也猜测有一种方法可以找出它是否是通过检查记录计数或类似的东西来连接。我只是不知道将如何归还,所以我不知道如何检查它们。我确实发现链表的记录数总是-1。如果BE断开连接,它是否仍会返回-1,因为它知道它是一个链接表,还是会返回其他内容?


刚刚测试了我的最后一次猜测,它仍然返回-1。还有其他类似的东西可以测试,如果没有连接会返回不同的值吗?

Is there a way to find out if all of the tables in the BE are connected? I would like to have a form open when the database is first opened. In its On_Load event, I want to check if all the tables are connected. If they are, then the form will close and the main form will open for the user to use the database. If the tables aren''t connected, then I will use the startup form to enter the BE name and file path to be passed to my ReLink function (which is being worked on in another thread). I just need to know how to check if the tables are connected. I have gone through all the TableDef properties on MSDN, but the information is very scarce. I couldn''t find anything that said "Check Connection", so I''m guessing that there isn''t anything explicitly for this, but I''m also guessing that there is a way of finding out if it is connected by checking something like record count or something like that. I just don''t know how things will be returned so I don''t know how to check for them. I did find out that the record count for a linked table will always be -1. If the BE is disconnected, would it still return a -1 because it knows that it is a linked table or would it return something else?

Just tested my last guess and it still returned -1. Is there anything else like that that could be tested and would return a different value if not connected?

推荐答案

我找到的唯一方法就是尝试打开在链接表上设置记录,尝试记录移动,并捕获错误。

我只在后端的一个链接表上执行此操作并假设它是否失败它们都会执行,如果它通过则他们都过去了;但是,您可以对tabledef中的每个附加表执行此操作。
The only way I''ve found is to attempt to open a record set on the linked table, try a record move, and trap for error.
I do this on just one linked table in the backend and assume if it fails they all do and if it passes then they all pass; however, you could do this for each attached table in the tabledefs.


我怀疑链接到空中的表上的任何操作都会导致Seth失败。


看来你有两个选择:
I suspect any action on a table linked to air would result in a failure Seth.

It seems you have two options :
  1. 以某种方式访问​​表并捕获错误。
  2. 从中识别文件名 .Connect 属性(您最近的其他线程有一个如何执行此操作的示例),并使用 Dir()检查该文件。如果需要,一些示例代码是:
  1. Access the table somehow and trap the error.
  2. Identify the file name from the .Connect property (Your other recent thread has an example of how to do this,) and check for that file using Dir(). Some example code, if required, is :
展开 | 选择 | Wrap | 行号


因此,选项2的工作原理基于(逻辑)假设,如果BE存在于FE认为的位置,那么存在连接吗?那讲得通。我会遍历TableDef,因为有可能存在多个BE文件(但不太可能),因此每个表都会将其位置传递给函数以检查是否为真。


我想到了整个画面,我看到了两个选择。如果表Exist()返回false,那么我可以立即跳转到我将重新链接所有表的位置,或者我可以将表添加到已断开连接的表的记录集。然后我将在ReLink函数中循环遍历该记录集。你会推荐哪一个?
So option 2 works based on the (logical) assumption that if the BE exists where the FE thinks it is, then there is a connection? That makes sense. And I would loop through the TableDefs because it is possible that there are multiple BE files (however unlikely that would be) so each table would pass its location to the function to check for true.

I thinking of the whole picture, I see two options. If a table Exist() comes back as false, then I could either immediately jump to where I would relink all the tables, or I could add the tables to a recordset of disconnected table. I would then loop through that recordset in the ReLink function. Which would you recommend?


这篇关于如何使用VBA查明是否所有表都已连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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