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.OpenRecordset(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("tblPersonal", "SSN", strSSN)
But when I use
blnExists("tblExamData", "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. 3 12379
The index may be named "PrimaryKey" instead of "ExamNum".
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"RBohannon" <ra*****@hotmail.com> wrote in message
news:ad**************************@posting.google.c om... 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.OpenRecordset(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("tblPersonal", "SSN", strSSN) But when I use blnExists("tblExamData", "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.
The default index for a primary key field is called
'PrimaryKey'. Open the table in design mode: right
click and select 'indexes' to see named indexes.
Index names don't change when you change field
names, and not all fields are automatically indexed.
"RBohannon" <ra*****@hotmail.com> wrote in message
news:ad**************************@posting.google.c om... 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.OpenRecordset(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("tblPersonal", "SSN", strSSN) But when I use blnExists("tblExamData", "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.
"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message news:<41***********************@news.syd.swiftdsl. com.au>... The default index for a primary key field is called 'PrimaryKey'. Open the table in design mode: right click and select 'indexes' to see named indexes. Index names don't change when you change field names, and not all fields are automatically indexed.
"RBohannon" <ra*****@hotmail.com> wrote in message news:ad**************************@posting.google.c om... 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.OpenRecordset(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("tblPersonal", "SSN", strSSN) But when I use blnExists("tblExamData", "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.
Right you are.
The reason the function worked with tblPersonal is because SSN was
indexed, but it was not the primary key.
I made the necessary changes, and now everything works OK.
Thank you both,
Randy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: titi |
last post by:
Question
The road and traffic authority for a small country currently uses a
system to store information about all 'currently' licensed drivers.
A licensed driver has the following info stored...
|
by: talfano |
last post by:
Hello,
We are having a very strange problem. We have a table with about 5
million rows in it. The problem is with one of the non clustered
indexes. I have noticed that sometimes in query...
|
by: sql_server_2000_user |
last post by:
Hi,
I have a table with about 305 million rows, and a composite primary key
that consists of an ascending int and an ascending varchar(18), which
is typically of length 13. Even if all the keys...
|
by: Average Bear |
last post by:
If anyone could help with this one, I am a bit puzzled. I understand
you can create an index using two fields of a database, then use the
seek method to find a record based on both fields. My...
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: ramnadh nalluri |
last post by:
Hi,
Below is the query that causing problems
SELECT T.Id AS TaskId
FROM dbo.Task T (NOLOCK)
INNER JOIN dbo.WorkOrder WO (NOLOCK) ON T.WorkOrderId = WO.Id
INNER JOIN dbo.StateMaster (NOLOCK)...
|
by: Yi Xing |
last post by:
Hi,
I need to read specific lines of huge text files. Each time, I know
exactly which line(s) I want to read. readlines() or readline() in a
loop is just too slow. Since different lines have...
|
by: HC |
last post by:
Hello, all, I started out thinking my problems were elsewhere but as I
have worked through this I have isolated my problem, currently, as a
difference between MSDE and SQL Express 2005 (I'll just...
|
by: jON Rowlan |
last post by:
I am slowing get my head around the concept of treating tables as
collections of rows as vb.net seems to prefer.
However, I have an indexed table in an Access database that I want to scan.
I...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |