删除关系...... [英] Deleting Relationships...

查看:69
本文介绍了删除关系......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码删除我的mdb文件中的所有关系


iFlag = 1

Do while iFlag<> 0

iFlag = 0

For each rel in db.Relations

db.Relations.Delete rel.Name

iFlag = 1

Next rel

循环


只循环一次只删除两个表之间的一个关系。我必须

重复循环以删除所有表之间的所有关系。是否有一些

外部容器或集合可以循环使用?另外,是否有一个

SQL语句,如DROP RELATION ...?


谢谢。


Matthew Wells
MW****@NumberCruncher.com

I''m using this code to delete all relationships in my mdb file

iFlag = 1
Do While iFlag <> 0
iFlag = 0
For Each rel In db.Relations
db.Relations.Delete rel.Name
iFlag = 1
Next rel
Loop

Just looping once only deletes one relation between two tables. I have to
repeat the loop to delete all relations between all tables. Is there some
outer container or collection that I can loop through? Also, is there an
SQL statement like "DROP RELATION..."?

Thanks.

Matthew Wells
MW****@NumberCruncher.com

推荐答案

Yick!


您不能使用For Each如果你要移除集合的成员。

尝试向后计数。


对于iRel = db.Relations.Count - 1到0步 - 1

db.Relations.Delete db.Relations(i).Name

Next iRel

-

MichKa [MS]


该帖子按原样提供。与

无保证,并且不授予任何权利。

" Matthew Wells" < MW **** @ NumberCruncher.com>在消息中写道

news:9f ****************** @ bignews6.bellsouth.net ..。
Yick!

You cannot use a "For Each" if you are removing members of the collection.
Try counting backwards to do this.

For iRel = db.Relations.Count - 1 to 0 Step -1
db.Relations.Delete db.Relations(i).Name
Next iRel
--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Matthew Wells" <MW****@NumberCruncher.com> wrote in message
news:9f******************@bignews6.bellsouth.net.. .
I我正在使用此代码删除我的mdb文件中的所有关系

iFlag = 1
Do While iFlag<> 0
iFlag = 0
For each rel in db.Relations
db.Relations.Delete rel.Name
iFlag = 1
Next rel
Loop

只循环一次只删除两个表之间的一个关系。我必须重复循环以删除所有表之间的所有关系。是否有一些我可以循环的外部容器或集合?另外,是否有像DROP RELATION ...这样的SQL语句?

谢谢。

Matthew Wells
MW **** @ NumberCruncher.com
I''m using this code to delete all relationships in my mdb file

iFlag = 1
Do While iFlag <> 0
iFlag = 0
For Each rel In db.Relations
db.Relations.Delete rel.Name
iFlag = 1
Next rel
Loop

Just looping once only deletes one relation between two tables. I have to
repeat the loop to delete all relations between all tables. Is there some
outer container or collection that I can loop through? Also, is there an
SQL statement like "DROP RELATION..."?

Thanks.

Matthew Wells
MW****@NumberCruncher.com



马修威尔斯 < MW **** @ NumberCruncher.com>写在

新闻:9f ****************** @ bignews6.bellsouth.net:
"Matthew Wells" <MW****@NumberCruncher.com> wrote in
news:9f******************@bignews6.bellsouth.net:
我正在使用此代码删除我的mdb文件中的所有关系

iFlag = 1
Do While iFlag<> 0
iFlag = 0
For each rel in db.Relations
db.Relations.Delete rel.Name
iFlag = 1
Next rel
Loop

只循环一次只删除两个表之间的一个关系。我有重复循环来删除所有表之间的所有关系。是否有一些我可以循环的外部容器或集合?另外,是否有像DROP RELATION ...这样的SQL语句?
I''m using this code to delete all relationships in my mdb file

iFlag = 1
Do While iFlag <> 0
iFlag = 0
For Each rel In db.Relations
db.Relations.Delete rel.Name
iFlag = 1
Next rel
Loop

Just looping once only deletes one relation between two tables. I have
to repeat the loop to delete all relations between all tables. Is there
some outer container or collection that I can loop through? Also, is
there an SQL statement like "DROP RELATION..."?




如果我没记错的话,对于每个构造都使用一个计数器和混淆
删除期间
。也就是说,如果有两个关系,我们首先在a中删除

,第二个变成#1,每个构造的

搜索关系#2 ,找不到它并退出。如果有两个以上的b
,则只删除奇数编号的关系。


删除所有关系的另一种方法可能是:


Sub RemoveRelations()

Dim dbs作为数据库

设置dbs = CurrentDb()

使用dbs

Do While .Relations.Count> 0

.Relations.Delete .Relations(.Relations.Count - 1).Name

Loop

.Relations.Refresh

结束

设置dbs =无任何

结束子


这是très古代代码。我已经多年没用了。如果您决定使用它,或者甚至批评它,请记住这个




-

Lyle

(电子邮件参考 http://ffdba.com/ contacts.htm


Mi ************@Invalid.Com (Lyle Fairfield)写道

< Xn ************* ****** @ 130.133.1.4>:
Mi************@Invalid.Com (Lyle Fairfield) wrote in
<Xn*******************@130.133.1.4>:
" Matthew Wells" < MW **** @ NumberCruncher.com>在
新闻中写道:9f ****************** @ bignews6.bellsouth.ne t:
"Matthew Wells" <MW****@NumberCruncher.com> wrote in
news:9f******************@bignews6.bellsouth.ne t:
我''使用此代码删除我的mdb文件中的所有关系

iFlag = 1
同时iFlag<> 0
iFlag = 0
For each rel in db.Relations
db.Relations.Delete rel.Name
iFlag = 1
Next rel
Loop <只需循环一次只删除两个表之间的一个关系。
我必须重复循环删除所有表之间的所有关系。我可以通过一些外部容器或集合吗?另外,是否存在类似DROP
RELATION ...的SQL语句?
如果我没记错的话,对于每个构造都使用计数器并在删除过程中混淆。也就是说,如果有两个关系
我们删除第一个中的第一个,第二个变为#1,
并且每个构造搜索关系#2,不会找到它并退出。如果有两个以上,只删除奇数
编号的关系。

删除所有关系的另一种方法可能是:

Sub RemoveRelations()
dim dbs作为数据库
设置dbs = CurrentDb()
使用dbs
Do While .Relations.Count> 0
.Relations.Delete .Relations(.Relations.Count -
1).Name
Loop
.Relations.Refresh
结束用
设置dbs =没什么
结束子

这是très古代代码。我已经多年没用了。如果您决定使用它,或者甚至批评它,请记住这一点。
I''m using this code to delete all relationships in my mdb file

iFlag = 1
Do While iFlag <> 0
iFlag = 0
For Each rel In db.Relations
db.Relations.Delete rel.Name
iFlag = 1
Next rel
Loop

Just looping once only deletes one relation between two tables.
I have to repeat the loop to delete all relations between all
tables. Is there some outer container or collection that I can
loop through? Also, is there an SQL statement like "DROP
RELATION..."?
If I remember correctly, for each constructs use a counter and get
confused during deletes. That is, if there are two relationships
and we delete the first within a for each, the second becomes #1,
and the for each construct searches for relationship #2, does not
find it and quits. If there are more than two, only the odd
numbered relationships are deleted.

Another way of deleting all relationships may be:

Sub RemoveRelations()
Dim dbs As Database
Set dbs = CurrentDb()
With dbs
Do While .Relations.Count > 0
.Relations.Delete .Relations(.Relations.Count -
1).Name
Loop
.Relations.Refresh
End With
Set dbs = Nothing
End Sub

This is très ancient code. I have not used it for years. Please,
bear this in mind if you decide to use it, or even criticize it.




从集合中删除项目时,我认为它''最好使用

MichKa方法,即使用计数器并使用STEP -1从

集合计数开始:

For iRel = db.Relations.Count - 1到0步骤-1
db.Relations.Delete db.Relations(i).Name
下一个iRel



When deleting items from a collection, I think it''s better to use
the MichKa method, which is to use a counter and start from the
collection count with STEP -1:
For iRel = db.Relations.Count - 1 to 0 Step -1
db.Relations.Delete db.Relations(i).Name
Next iRel




我建议这样做的原因是,从集合属性中查找值的依赖性较小。

也就是说,在

MichKa的方法中,您查找集合计数,然后按索引号对集合成员运行

。在你的例子中,你看一下循环的收集计数一次是
,然后循环中的每个

项目看一次。


-

David W. Fenton http:// www .bway.net / ~dfenton

dfenton at bway dot net http://www.bway.net/~dfassoc


这篇关于删除关系......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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