做...循环问题 - 插入相同的记录 [英] Do...Loop Problem - Inserting same record

查看:60
本文介绍了做...循环问题 - 插入相同的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向大家致意,


我正在研究一个调度工具,并且有一个临时表,我试图循环以从删除之前提取必要的信息。


我在Windows XP上使用Access''97。


这是我的代码:

Greetings everyone,

I am working on a scheduling tool and have a temp table that I am attempting to loop through to pull the necessary info out of before deleting.

I am using Access ''97 on Windows XP.

Here is my code:

展开 | 选择 | Wrap | 行号

推荐答案


问候大家,


我正在研究一个调度工具,并且有一个临时表,我试图在删除之前循环删除所需的信息。


我在Windows XP上使用Access''97。


这是我的代码:

Greetings everyone,

I am working on a scheduling tool and have a temp table that I am attempting to loop through to pull the necessary info out of before deleting.

I am using Access ''97 on Windows XP.

Here is my code:

展开 | 选择 | Wrap | 行号



1.尝试删除这些行。您正在所有记录的字段中插入值;你没有使用价值陈述:

& " VALUES(PartNum,GB1,Qty,bucketDay,Dia,Length,SetupT ime,S1," _

& ActTime&",& RunHours&",#" ;& StartTime&"#,#"& EndTime&"#);"


2.更改此项:Dim ScheduleParts As Recordset

to:Dim ScheduleParts As DAO.Recordset


和更改:Dim db As Database

toL Dim db As DAO.Database


3.更改此:ScheduleParts.MoveFirst

至:

如果不是(.EOF或.BOF)那么

ScheduleParts.MoveFirst

结束如果
1. Try eliminating these lines. You are inserting the values in the fields for all records; you don''t use a values statement:
& " VALUES(PartNum,GB1,Qty,bucketDay,Dia,Length,SetupT ime,S1," _
& ActTime & "," & RunHours & ",#" & StartTime & "#,#" & EndTime & "#);"

2. Change this: Dim ScheduleParts As Recordset
to: Dim ScheduleParts As DAO.Recordset

and Change: Dim db As Database
toL Dim db As DAO.Database

3. Change this: ScheduleParts.MoveFirst
to:
If Not (.EOF Or .BOF) Then
ScheduleParts.MoveFirst
End If



感谢您的回复。我做了改变,但仍然没有得到我需要的循环。


删除值 SQL语句的一部分,是否需要将其替换为Insert Into ... Select ... From?我已经注释掉了我的SQL,并为部件号设置了一个MsgBox。它给了我第一次记录9次...有什么想法吗?

Thank you for your reply. I have made the changes and am still not getting the loop I need.

By removing the "values" portion of the SQL statement, do I need to replace it with a "Insert Into...Select...From"? I have commented out my SQL and have a MsgBox for the part number. It gives me the first record 9 times still...Any thoughts?

展开 | 选择 | Wrap < span class =codeDivider> | 行号


oops!我没在想。您已将记录集与sql语句组合在一起。 sql语句不是记录集循环的一部分。它将单独执行。真正的记录集数据需要.Edit和.Update命令。


请尝试下面的修订代码:
oops! I wasn''t thinking. You''ve combined a recordset with an sql statement. The sql statement is not part of the recordset loop..it will execute separately. The true recordset data needs .Edit and .Update commands.

Try the revised code below:
展开 | 选择 | Wrap | 行号


这篇关于做...循环问题 - 插入相同的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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