在插入之前检查表问题中的现有数据 [英] check for existing data in table issue before insertion

查看:70
本文介绍了在插入之前检查表问题中的现有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好社区专家,


有没有人知道如何检查MS Acess表中的现有数据?我已经使用vb尝试了以下代码,但似乎没有那么好用吗?任何人都可以看看这个代码/逻辑,如果可能的话指出错误或进行纠正?


我需要的是在插入之前检查现有的studentId和名字。如果表中存在插入的值,则消息重复。否则插入。


或者,我也希望通过使用student表中的studentid来组合一个组合框,检查学生表的重复值,如果找到插入的话失败,否则激活文本框提示用户输入插入,但也不能确定在vb环境中使用boolean来实现此目的。我已提供相关信息以便更加了解。 Tks!

桌面设计

S / No - 自动编号

StudentId - 文字pk

名称 - 文字

表格设计

StudentId - 未绑定文本框

名称 - 未绑定文本框

按钮 - 插入

Hi guys & commnunity experts,

Does anyone knw how to go about checking for existing data in an MS Acess table? I have tried out the following code using vb but doesnt seem to work that well? Can anyone ps take a look at this code / logic and if possible point out the error or make correction?

What i need is to check for existing studentId and name before insertion. If the inserted value existed in the table, message "duplicate" else insert.

Alternatively, i also want to do it in the way by implmenting a combo box with the studentid from the student table, check for duplicate value against student table, if found insert failed else activate the textbox prompt user input for insertion but nt too sure as to hw to use boolean in vb environment to acheive this. I have provided the relevant information for more understanding. Tks!

Table design
S/No - auto number
StudentId - text pk
Name - text

Form design
StudentId - unbound textbox
Name - unbound textbox
Button - Insert

Code

展开 | 选择 | 换行 | 行号

推荐答案

首先,请允许我说这个问题比一些我更乐于帮助的问题要好得多。

最简单的方法检查记录是否使用DLoo kup()函数,但使用记录集也是一种可行的方法。为了简化,我将使用DLookup()显示代码。我假设桌子的名字是tblStudent。

这个代码可以通过复制/粘贴原样使用,但是我已经打破了这里显示的行,这在我看来并不是完全必要的。你正确的代码模块。
Firstly, let me say that this question is so much better formulated than some that I''m happy to help if I can.
The easiest way to check for a record is to use the DLookup() function but using recordsets is a workable way too. To simplify I''ll just show code using DLookup(). I''m assuming the name of the table is tblStudent.
This code is usable by copying/pasting as it is but I''ve broken the lines for display in here which is not entirely necessary in your proper code module.
展开 | 选择 | Wrap | 行号



大家好&社区专家,


有没有人知道如何检查MS Acess表中的现有数据?我已经使用vb尝试了以下代码,但似乎没有那么好用吗?任何人都可以看看这个代码/逻辑,如果可能的话指出错误或进行纠正?


我需要的是在插入之前检查现有的studentId和名字。如果表中存在插入的值,则消息重复。否则插入。


或者,我也希望通过使用student表中的studentid来组合一个组合框,检查学生表的重复值,如果找到插入的话失败,否则激活文本框提示用户输入插入,但也不能确定在vb环境中使用boolean来实现此目的。我已提供相关信息以便更加了解。 Tks!

桌面设计

S / No - 自动编号

StudentId - 文字pk

名称 - 文字

表格设计

StudentId - 未绑定文本框

名称 - 未绑定文本框

按钮 - 插入

Hi guys & commnunity experts,

Does anyone knw how to go about checking for existing data in an MS Acess table? I have tried out the following code using vb but doesnt seem to work that well? Can anyone ps take a look at this code / logic and if possible point out the error or make correction?

What i need is to check for existing studentId and name before insertion. If the inserted value existed in the table, message "duplicate" else insert.

Alternatively, i also want to do it in the way by implmenting a combo box with the studentid from the student table, check for duplicate value against student table, if found insert failed else activate the textbox prompt user input for insertion but nt too sure as to hw to use boolean in vb environment to acheive this. I have provided the relevant information for more understanding. Tks!

Table design
S/No - auto number
StudentId - text pk
Name - text

Form design
StudentId - unbound textbox
Name - unbound textbox
Button - Insert

Code

展开 | 选择 | 换行 | 行号


请各位提示回复


这篇关于在插入之前检查表问题中的现有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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