是否可以在循环中使用ADODB.Recordset.Open [英] Is it possible to use ADODB.Recordset.Open in a loop

查看:47
本文介绍了是否可以在循环中使用ADODB.Recordset.Open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重新格式化excel表以便更方便访问并且必须使用记录集,但是我有多个表,我试图使用vba重新格式化为1个新表。当使用函数recordset.open时,第一个参数是Source,并且是我放置表名的地方。为了使这个工作,我试图建立一个循环,它将通过tab1,tab2,tab(n)但我不断收到错误。是否可以在此函数中循环表名? Access 2007

I am reformatting an excel sheet to be more access friendly and had to use a recordset, however i have multiple tables that im trying to reformat into 1 new table using vba. When using the function recordset.open the first parameter is Source, and is where i put a table name. To get this to work i tried to establish a loop where it would go through tab1, tab2, tab(n) but i kept getting errors. Is it possible to loop through table names in this function? Access 2007

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

推荐答案

不知道但肯定是tab &安培;英寸×"将始终给出一个字符串tabx。


下一个问题是TableDefs集合包括system&隐藏文件,例如MsysObjects等。 &安培; " MSysRelationships"可能大约有13个系统表。


下一个非常小的问题是TableDefs计数从0开始。


我不知道这是否会工作,但它更接近

Don''t know but certainly "tab" & "x" will always give a string "tabx".

Next problem is that the TableDefs collection includes system & hidden files such as "MsysObjects" & "MSysRelationships" Probably about 13 system tables.

Next very minor problem is that the TableDefs count starts at 0.

I have no idea if this will work, but it''s closer

展开 | 选择 | Wrap | 行号


似乎更接近我想要的东西,等等灵活,但它返回相同的错误无效的SQL语句;预期''删除'',''插入'',''程序'',''选择''或''更新''。如果那里有一个标准的表名,这对它起作用似乎很奇怪,谢谢你,但是
Seems a lot closer to what im wanting, and more flexible, however it returns the same error of "Invalid SQL statement; expected ''DELETE'', ''INSERT'', ''PROCEDURE'', ''SELECT'', or ''UPDATE''." which seems odd do to it working if there''s a standard table name there, thank you though

我很遗憾地说这看起来有些不整洁。我看不出你想做什么。没有什么我能想到你可能想做的事情是有意义的。


OTOH,你的直接问题似乎是试图在错误的位置使用位置参数。


我的建议是尽可能使用命名参数。它可以减少错误,并且更加自我记录。谁想要处理某个人的代码,列出多参数程序的参数?没什么好玩的。


你从哪里出发当然是另一个问题。
I''m sorry to say this looks a bit untidy. I can''t see what you''re trying to do. Nothing that I can think of that you may be trying to do makes sense.

OTOH, your immediate problem appears to be trying to use positional parameters in the wrong position.

My advice is to use named parameters where possible. It leads to fewer errors and it''s more self-documenting. Who wants to have to work on someone''s code that lists the parameters to multi-parameter procedures? Not fun.

Where you go from there is another issue of course.


这篇关于是否可以在循环中使用ADODB.Recordset.Open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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