473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

vba for seeing if a field in a table is indexed

I have a table called "tblParticipants" with a field called "ID", which must
be indexed with No duplicates allowed. I am looking for a way of doing in
vba a small if ..then ..else .. routine that looks at that field in that
table and if it is not indexed, indexes it, and if it is indexed, jumps to a
label. I have a query called "qryAddIndex" that will index the field, what
I really need is the vba to test if the field is indexed or not.

dixie
Nov 12 '05 #1
4 2574
"dixie" <di****@dogmail.com> wrote in
news:oZ****************@nnrp1.ozemail.com.au:
I have a table called "tblParticipants" with a field called "ID", which
must be indexed with No duplicates allowed. I am looking for a way of
doing in vba a small if ..then ..else .. routine that looks at that
field in that table and if it is not indexed, indexes it, and if it is
indexed, jumps to a label. I have a query called "qryAddIndex" that
will index the field, what I really need is the vba to test if the field
is indexed or not.

dixie


Assuming >= AC2K

you could try

Public Function IsColumnUniquelyIndexed(ByVal TableName As String, ByVal
ColumnName As String) As Boolean
IsColumnUniquelyIndexed = Not CurrentProject.Connection.OpenSchema
(adSchemaConstraintColumnUsage, Array(Empty, Empty, TableName,
ColumnName)).BOF
End Function

Sub TestIsColumnUniquelyIndexed()
MsgBox IsColumnUniquelyIndexed("tbl2002Transactions", "fldDate")
' returns true
End Sub
--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #2
Unless I'm mis-understanding you, indexing the field is done in table
design, and stays that way unless you change it.
It's not a per record type of property.

Mike Storr
www.veraccess.com
"dixie" <di****@dogmail.com> wrote in message
news:oZ****************@nnrp1.ozemail.com.au...
I have a table called "tblParticipants" with a field called "ID", which must be indexed with No duplicates allowed. I am looking for a way of doing in
vba a small if ..then ..else .. routine that looks at that field in that
table and if it is not indexed, indexes it, and if it is indexed, jumps to a label. I have a query called "qryAddIndex" that will index the field, what I really need is the vba to test if the field is indexed or not.

dixie

Nov 12 '05 #3
Lyle Fairfield <Mi************@Invalid.Com> wrote in
news:Xn*******************@130.133.1.4:
"dixie" <di****@dogmail.com> wrote in
news:oZ****************@nnrp1.ozemail.com.au:
I have a table called "tblParticipants" with a field called "ID", which
must be indexed with No duplicates allowed. I am looking for a way of
doing in vba a small if ..then ..else .. routine that looks at that
field in that table and if it is not indexed, indexes it, and if it is
indexed, jumps to a label. I have a query called "qryAddIndex" that
will index the field, what I really need is the vba to test if the field
is indexed or not.

dixie


Assuming >= AC2K

you could try

Public Function IsColumnUniquelyIndexed(ByVal TableName As String, ByVal
ColumnName As String) As Boolean
IsColumnUniquelyIndexed = Not CurrentProject.Connection.OpenSchema
(adSchemaConstraintColumnUsage, Array(Empty, Empty, TableName,
ColumnName)).BOF
End Function

Sub TestIsColumnUniquelyIndexed()
MsgBox IsColumnUniquelyIndexed("tbl2002Transactions", "fldDate")
' returns true
End Sub


Well ... I suppose some might find the preceding obscure:

so you might use:

Public Function IsColumnUniquelyIndexed2(ByVal TableName As String, ByVal
ColumnName As String) As Boolean
WizHook.Key = 51488399
IsColumnUniquelyIndexed2 = WizHook.TableFieldHasUniqueIndex(TableName,
ColumnName)
End Function

Sub temp2()
MsgBox IsColumnUniquelyIndexed2("tbl2002Transactions",
"fldTransactionID")
' shows true
End Sub

Of course, be careful with line breaks.

The nice thing about the first is that it returns true for any column which
is part of a unique index, while the second does not, dealing with only
single column indexes, it SEEMS. One would think one could send more than
one column name to the second, but I have not found a way to do this.
--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #4
Hi Mike, I am actually exporting a recordset using Docd.TransferDatabase
into another database and when it arrives at the other database, the primary
key and indexes have disappeared. The application needs the indexing on the
ID field to be there. The version is A2k.

dixie

"Mike Storr" <st******@sympatico.ca> wrote in message
news:dE******************@news20.bellglobal.com...
Unless I'm mis-understanding you, indexing the field is done in table
design, and stays that way unless you change it.
It's not a per record type of property.

Mike Storr
www.veraccess.com
"dixie" <di****@dogmail.com> wrote in message
news:oZ****************@nnrp1.ozemail.com.au...
I have a table called "tblParticipants" with a field called "ID", which must
be indexed with No duplicates allowed. I am looking for a way of doing in vba a small if ..then ..else .. routine that looks at that field in that
table and if it is not indexed, indexes it, and if it is indexed, jumps

to a
label. I have a query called "qryAddIndex" that will index the field,

what
I really need is the vba to test if the field is indexed or not.

dixie


Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John | last post by:
Hello, I have a table called BUILDREQUESTS which I want to select from, depending on the project ID of each record. The Project ID field is indexed. (A) This query runs almost instantly: ...
1
by: Old Timer | last post by:
I wish to type in a number in my "Code" field, for instance 1060, I then wish the number 1060 to trigger an event that will fill in the next field (township field) For instance, 1060 brings up and...
1
by: GGerard | last post by:
Hello I am working with Access 2000 I have two tables joined on a one to many relationship between two fields: Table1:FieldID (one) is joined to Table2:FieldMyID (many) Field Properties...
6
by: Larry R Harrison Jr | last post by:
I have a database I'm designing in Access 97. I have a custom field in a query which looks in {Table of Documents} and shows them all. It then needs a "latest revision number," stored in another...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
1
by: ing42 | last post by:
I have a problem with inserting records into table when an indexed view is based on it. Table has text field (without it there is no problem, but I need it). Here is a sample code: USE test GO...
13
by: paquer | last post by:
Ok' I have 2 tables. The first being my main table where each record has a 'FigureID' txt box. (Indexed - No duplicates) The second being my sub table where reporting is entered for these...
25
by: Rick Collard | last post by:
Using DAO 3.6 on an Access 2002 database, I'm getting unexpected results with the FindFirst method. Here's the simple code to test: Public Sub FindIt() Dim db As Database, rs As Recordset...
1
jinalpatel
by: jinalpatel | last post by:
I am dealing with 3 tables. Here is a brief meta data see the attachment for the relationship Conditions: 1)One GrantIndex can have multiple Deliverables 2)one Deliverable is made from...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.