I'm using Access 2000.
I've written a function, blnExists(), to check if a particular value
exists in the primary key field of a table. blnExists returns true if
the value is in the table and false if not.
Public Function blnExists(strRS As String, _
strIndex As String, _
strTarget As String) As Boolean
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordse t(strRS)
rs.Index = strIndex
rs.Seek "=", strTarget
If rs.NoMatch = True Then
blnExists = False
Else
blnExists = True
End If
rs.Close
End Function
where strRS is the recordset to be searched, strIndex is the Index of
the recordset, and strTarget is the value being searched for.
The function works with
blnExists("tblP ersonal", "SSN", strSSN)
But when I use
blnExists("tblE xamData", "ExamNum", strExam)
I get an error message: Run-time error '3800' : 'ExamNum' is not an
index in this table.
and execution stops at
rs.Index = strIndex
But ExamNum is the primary key field of tblExamData; Indexed == Yes(No
Duplicates).
Can anyone suggest why this is happening and how to fix it?
Thank you for your consideration.
I've written a function, blnExists(), to check if a particular value
exists in the primary key field of a table. blnExists returns true if
the value is in the table and false if not.
Public Function blnExists(strRS As String, _
strIndex As String, _
strTarget As String) As Boolean
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordse t(strRS)
rs.Index = strIndex
rs.Seek "=", strTarget
If rs.NoMatch = True Then
blnExists = False
Else
blnExists = True
End If
rs.Close
End Function
where strRS is the recordset to be searched, strIndex is the Index of
the recordset, and strTarget is the value being searched for.
The function works with
blnExists("tblP ersonal", "SSN", strSSN)
But when I use
blnExists("tblE xamData", "ExamNum", strExam)
I get an error message: Run-time error '3800' : 'ExamNum' is not an
index in this table.
and execution stops at
rs.Index = strIndex
But ExamNum is the primary key field of tblExamData; Indexed == Yes(No
Duplicates).
Can anyone suggest why this is happening and how to fix it?
Thank you for your consideration.
Comment