本文介绍了使用seek查找是否存在记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试使用seek来检查 保存之前是否存在记录,因此没有重复的条目(还有其他方法吗?)。我/ b $ b有一个群组桌子,已经 GroupID 岛 GroupName 我的代码权限现在给我一个类型不匹配错误,这就是 看起来像: Dim rsGroups作为记录集 设置rsGroups = CurrentDb.OpenRecordset(" ; tblGroups") rsGroups.Seek Form_frmGroups.txtGroupName 如果rsGroups.EOF那么 MsgBox"找不到值 ''DoCmd.Save ''Form_frmGroups.AllowAdditions = False ''Form_frmGroups.AllowEdits =错误 其他 MsgBox已在数据库中找到的价值 结束如果 有人可以提供一些建议或提示吗? 凯文 I''m trying to use seek to check for the existence of a record beforesaving, so there are no duplicate entries (is there another way?). Ihave a "groups" table, which has GroupIDIslandGroupName My code right now is giving me a "type mismatch" error, and this is whatit looks like: Dim rsGroups As RecordsetSet rsGroups = CurrentDb.OpenRecordset("tblGroups") rsGroups.Seek Form_frmGroups.txtGroupName If rsGroups.EOF ThenMsgBox "Value not found" '' DoCmd.Save'' Form_frmGroups.AllowAdditions = False'' Form_frmGroups.AllowEdits = False ElseMsgBox "Value already found in database" End If Can anyone offer some suggestions or hints? Kevin推荐答案 实际上,你可以。查看附表。 诀窍是调暗/设置指向表所在数据库的指针。 例如 ----------------------------- -------------------------------------- Public Function EmployeeExist( byVal theEmployeeNumber As Long)As Boolean 将myDB作为DAO.Database调暗 将myRS视为DAO.Recordset 设置myDB = dbEngine(0).OpenDatabase(" M:\Whatever\Payroll.mdb") 设置myRS = myDB.OpenRecordset(" tblEmployee",dbOpenTable ) with myRS .Index =" PrimaryKey" .Seek" =" ;,EmployeeNumber 如果.NoMatch = False那么 EmployeeExist = True 结束如果 (或者,如果你想变得可爱:EmployeeExist = Not .NoMatch 。关闭 结束 设置myRS = Nothing 设置myDB = Nothing 结束功能 ----- -------------------------------------------------- ------------ - PeteCresswell Actually, you can .Seek an attached table. The trick is to Dim/Set a pointer to the database that the table is in. e.g.-------------------------------------------------------------------Public Function EmployeeExist(byVal theEmployeeNumber As Long) As Boolean Dim myDB as DAO.DatabaseDim myRS As DAO.Recordset Set myDB = dbEngine(0).OpenDatabase("M:\Whatever\Payroll.mdb" ) Set myRS = myDB.OpenRecordset("tblEmployee", dbOpenTable)With myRS.Index = "PrimaryKey".Seek "=", theEmployeeNumberIf .NoMatch = False ThenEmployeeExist = TrueEnd If(or, if you want to be cute: EmployeeExist = Not .NoMatch.CloseEnd With Set myRS = Nothingset myDB = NothingEnd Function ---------------------------------------------------------------------PeteCresswell 实际上,你可以。查看附表。 诀窍是Dim / Set指向表所在数据库的指针。 例如 --------------------------------------------- ---------------------- Public Function EmployeeExist(byVal theEmployeeNumber As Long)as Boolean 将myDB作为DAO调暗。数据库 DIM myRS作为DAO.Recordset 设置myDB = dbEngine(0).OpenDatabase(" M:\Whatever\Payroll.mdb") >设置myRS = myDB.OpenRecordset(" tblEmployee",dbOpenTable)使用myRS .Index =" PrimaryKey" .Seek" =" ;,EmployeeNumber 如果.NoMatch = False然后 EmployeeExist = True 结束如果(或者,如果你想变得可爱:EmployeeExist =不.NoMatch 。关闭结束 设置myRS = Nothing 设置myDB = Nothing 结束功能 - -------------------------------------------------- ---------------- Actually, you can .Seek an attached table. The trick is to Dim/Set a pointer to the database that the table is in. e.g. ------------------------------------------------------------------- Public Function EmployeeExist(byVal theEmployeeNumber As Long) As Boolean Dim myDB as DAO.Database Dim myRS As DAO.Recordset Set myDB = dbEngine(0).OpenDatabase("M:\Whatever\Payroll.mdb" ) Set myRS = myDB.OpenRecordset("tblEmployee", dbOpenTable) With myRS .Index = "PrimaryKey" .Seek "=", theEmployeeNumber If .NoMatch = False Then EmployeeExist = True End If (or, if you want to be cute: EmployeeExist = Not .NoMatch .Close End With Set myRS = Nothing set myDB = Nothing End Function ------------------------------------------------------------------- 当鸭子鸣喇叭时,他们就是鹅。 - Lyle Fairfield When ducks honk they are geese. --Lyle Fairfield 这篇关于使用seek查找是否存在记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 02:38