ACCESS/VBA:使用自动编号字段插入会返回烦人的警告
好的,情况是这样的
让我们看一下表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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Microsoft Access 无法添加更新或追加查询中的所有记录。
由于类型转换失败,它将 1 个字段设置为 Null。
该错误与您的自动编号字段无关。检查字段B和C的数据类型。
在这个例子中,字段C设置为数字,所以我得到了和你一样的错误,并且INSERT成功,但字段C为空:
然而,将数字值插入字段C工作正常。
编辑:尽管为字段 C 提供了文本值,此方法也可以工作。不同之处在于文本值是数据库引擎可以转换为有效数字的值:
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:
However, inserting a numeric value into field C works fine.
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:
这显然是由于自动编号字段造成的吗?添加记录后(单击“仍然运行”运行查询),只有自动编号字段为空?
自动编号不应发生此错误;至少,我以前从未见过。
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.
听起来您正在向其中一个值传递一个空字符串,并将该列设置为 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
Do all of the fields get populated correctly? Including the Autonumber?