无法插入记录 [英] Trouble inserting records

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

问题描述

早上好,


我正在使用一个基本上将'用户窗口登录ID,名字和姓氏添加到表中的表单。然后,一旦添加显示此表中的名称,就会重新获取此表单上的列表框。我最终试图让它成为用户无法在此表中添加两次信息。好吧,你会认为只是让他们的ID表中的PK会起作用,但是我遇到了这个问题。


用户单击命令按钮,其信息将通过绑定文本框插入到表中。然后,他们再次单击命令按钮,我收到一条错误消息您对表所请求的更改未成功,因为它们会创建重复值blah blah。但是,这只是第一次发生。如果我从列表框中删除记录并再次添加副本,我只会得到你不能去指定的记录。 yadda yadda。我最终希望它只是没有添加重复记录,如果有一个并提示错误消息并继续。


所以,我试图使用DCount程序来验证ID isn在尝试添加记录之前在表中,这似乎有效,当我在表单最初打开时尝试创建重复记录时,我收到我的错误消息,他们已经在队列中,但后来我收到了访问消息,由于重复记录,更改不成功,就好像它正在尝试仍然添加记录一样。我在代码中停了一下,确认它正在跳过添加新记录,所以我不确定这是怎么回事。这是我的代码:

Good Morning,

I''m working with a form that basically add''s a users windows logon ID, first name, and last name to a table. A list box on this form is then requeried once added displaying the names in this table. I''m ultimately trying to make it so the user can''t add their information twice in this table. Well, you would think just making their ID the PK in the table would work, however I''m running into an issue with this.

The user clicks the command button and their info is inserted into the table by bound text boxes. Then, they click the command button again and I receive an error message that "The changes you requested to the table were not successfull because they would create duplicate values blah blah". But, this only happens on the first time. If I remove the record from the list box and add a duplicate again I only get "You can''t go to the specified record" yadda yadda. I ultimately would like it to just not add the duplicate record if there is one and prompt an error message and continue.

So, I tried to use a DCount procedure to verify the ID wasn''t in the table before attempting to add the record, this seems to work, when I attempt to create a dup record when the form is initially opened I receive my error message that they are already in the queue, but then I receive the access message that the changes weren''t successful due to a duplicate record, as if it''s attempting to still add the record. I placed a stop in the code and verified it was skipping over the add new record, so I''m not sure how this was. Here is my code:

展开 | 选择 | Wrap | 行号

推荐答案


早上好,


我正在使用一个基本上将用户的Windows登录ID,名字和姓氏添加到表中的表单。然后,一旦添加显示此表中的名称,就会重新获取此表单上的列表框。我最终试图让它成为用户无法在此表中添加两次信息。好吧,你会认为只是让他们的ID表中的PK会起作用,但是我遇到了这个问题。


用户单击命令按钮,其信息将通过绑定文本框插入到表中。然后,他们再次单击命令按钮,我收到一条错误消息您对表所请求的更改未成功,因为它们会创建重复值blah blah。但是,这只是第一次发生。如果我从列表框中删除记录并再次添加副本,我只会得到你不能去指定的记录。 yadda yadda。我最终希望它只是没有添加重复记录,如果有一个并提示错误消息并继续。


所以,我试图使用DCount程序来验证ID isn在尝试添加记录之前在表中,这似乎有效,当我在表单最初打开时尝试创建重复记录时,我收到我的错误消息,他们已经在队列中,但后来我收到了访问消息,由于重复记录,更改不成功,就好像它正在尝试仍然添加记录一样。我在代码中停了一下,确认它正在跳过添加新记录,所以我不确定这是怎么回事。这是我的代码:

Good Morning,

I''m working with a form that basically add''s a users windows logon ID, first name, and last name to a table. A list box on this form is then requeried once added displaying the names in this table. I''m ultimately trying to make it so the user can''t add their information twice in this table. Well, you would think just making their ID the PK in the table would work, however I''m running into an issue with this.

The user clicks the command button and their info is inserted into the table by bound text boxes. Then, they click the command button again and I receive an error message that "The changes you requested to the table were not successfull because they would create duplicate values blah blah". But, this only happens on the first time. If I remove the record from the list box and add a duplicate again I only get "You can''t go to the specified record" yadda yadda. I ultimately would like it to just not add the duplicate record if there is one and prompt an error message and continue.

So, I tried to use a DCount procedure to verify the ID wasn''t in the table before attempting to add the record, this seems to work, when I attempt to create a dup record when the form is initially opened I receive my error message that they are already in the queue, but then I receive the access message that the changes weren''t successful due to a duplicate record, as if it''s attempting to still add the record. I placed a stop in the code and verified it was skipping over the add new record, so I''m not sure how this was. Here is my code:

展开 | 选择 | Wrap | 行号


美丽。非常感谢!


再次感谢您的帮助。我有另一个问题....我在表单上有一个刷新命令按钮,如果他们被另一个用户添加,则重新查询列表框以显示更新的记录。我每隔5秒钟就会把这个形式的ontimer事件播放到Me.Refresh。这似乎有效,但由于刷新,表格变得相当不稳定。有没有更好的方法让列表框与表同步而对用户部分没有任何作用?
Thanks again for the help. I have another question....I have a refresh command button on the form that requeries the listbox to show updated records if they''re added by another user. I''m playing with the ontimer event of the form to Me.Refresh every 5 seconds. This seems to work, however the form becomes fairly choppy because of the refreshes. Is there a better way for a listbox to be in sync with the table with no work on the users part?


这篇关于无法插入记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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