ACCESS/VBA:使用自动编号字段插入会返回烦人的警告

发布于 2024-10-17 06:41:33 字数 600 浏览 4 评论 0原文

好的,情况是这样的
让我们看一下表1(A,B,C)
A 是自动编号字段。

我正在通过 vba 向表提供数据。
由于 A 是自动编号,所以我像这样忽略它:

SQL = INSERT INTO TABLE1(B,C) VALUES ('something','something else')
DoCmd.RunSQL SQL

这工作正常,访问给了我第一个警告,我将创建一个新行。
这对我来说没问题。然而就在那之后我得到了这个:

Microsoft Access 无法添加更新或追加查询中的所有记录。
由于类型转换失败,它将 1 个字段设置为 Null。
blahblahblah 单击“确定”仍然运行查询

如果我单击“确定”,这不会阻止它工作,但我不希望我的用户看到 那个警告。
无论如何,为什么它会弹出?将自动编号字段留空不是很正常吗?
还有其他我不知道的程序吗?我缺少什么?

我环顾谷歌和这里,但找不到答案:/

(我不想将警告设置为 false,因为我希望添加字段的第一个警告和任何其他最终错误可见。)

Ok, here's the situation
Let's have Table1(A,B,C)
A is an autonumbering field.

I'm feeding the table via vba.
Since A is autonumbering, I'm ignoring it like so:

SQL = INSERT INTO TABLE1(B,C) VALUES ('something','something else')
DoCmd.RunSQL SQL

This works ok, access gives me a 1st warning that I'll be creating a new row.
Which is ok to me. However just after that I get this:

Microsoft Access can't add all the records in the update or append query.
It set 1 field(s) to Null due to a type conversion failure.
blahblahblah click ok to run the query anyway

Which doesn't prevent it from working if I click ok, but I don't want my user to see
that warning.
And anyway why does it pop up ? Isn't it normal to leave the autonumbering field blank ?
Is there another procedure I don't know about ? What am I missing ?

I looked around google and here but couldn't find an answer :/

(I don't want to setwarnings to false since I want the first warning of adding a field and any other eventual error to be visible.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鸠魁 2024-10-24 06:41:33

Microsoft Access 无法添加更新或追加查询中的所有记录。
由于类型转换失败,它将 1 个字段设置为 Null。

该错误与您的自动编号字段无关。检查字段B和C的数据类型。

在这个例子中,字段C设置为数字,所以我得到了和你一样的错误,并且INSERT成功,但字段C为空:

DoCmd.RunSQL "INSERT INTO TABLE1(B,C) VALUES ('something','something else')"

然而,将数字值插入字段C工作正常。

DoCmd.RunSQL "INSERT INTO TABLE1(B,C) VALUES ('something',99)"

编辑:尽管为字段 C 提供了文本值,此方法也可以工作。不同之处在于文本值是数据库引擎可以转换为有效数字的值:

DoCmd.RunSQL "INSERT INTO TABLE1(B,C) VALUES ('something','27')"

Microsoft Access can't add all the records in the update or append query.
It set 1 field(s) to Null due to a type conversion failure.

That error has nothing to do with your autonumber field. Check the data types of fields B and C.

In this example, field C is set to number, so I get the same error as you, and the INSERT succeeds but with Null in field C:

DoCmd.RunSQL "INSERT INTO TABLE1(B,C) VALUES ('something','something else')"

However, inserting a numeric value into field C works fine.

DoCmd.RunSQL "INSERT INTO TABLE1(B,C) VALUES ('something',99)"

Edit: This one also works in spite of supplying a text value for field C. The difference is the text value is one the database engine can convert to a valid number:

DoCmd.RunSQL "INSERT INTO TABLE1(B,C) VALUES ('something','27')"
鯉魚旗 2024-10-24 06:41:33

这显然是由于自动编号字段造成的吗?添加记录后(单击“仍然运行”运行查询),只有自动编号字段为空?

自动编号不应发生此错误;至少,我以前从未见过。

Is it clearly due to the autonumbering field? Once the record is added (running the query clicking on 'run anyway'), only the autonumber field is blank?

This error shouldn't be happening for Autonumber; at least, I've never seen it before.

时光清浅 2024-10-24 06:41:33

听起来您正在向其中一个值传递一个空字符串,并将该列设置为 NULL。

当你说

这并不妨碍它工作
如果我点击“确定”

所有字段都会正确填充吗?包括自动编号吗?

It sounds like you are passing in an empty string to one of the values and it's setting that column to NULL.

When you say

Which doesn't prevent it from working
if I click ok

Do all of the fields get populated correctly? Including the Autonumber?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文