How do I find if an Index exists?

saqi_the_angel

New member
Local time
Today, 11:47
Joined
Aug 24, 2006
Messages
2
Hi Guys,

Is it possible to find out if there is an Index on a table or not? I am using VB6 and Microsoft Access database? please don't ask y!!!

TIA

STA
 
Hi,

This is the syntax for VBA, probably very similar for vb6 - you'll need a proper connection string to the db i guess. Any way hope it helps.

K.

Code:
Dim db As DAO.Database
Dim tbldf As DAO.TableDef
Dim idx As index

Set db = CurrentDb
Set tbldf = db.TableDefs("Table1")


For Each idx In tbldf.Indexes

MsgBox idx.Name

Next idx


Set db = Nothing
Set tbldf = Nothing
 
Karma,

thanks for your reply. the function below comes up with error user defind type not defind. Please accept my apologies I am very new to programming.

Public Function CheckIndex()

Dim db As DAO.Database
Dim tbldf As DAO.TableDef
Dim idx As index
Dim empindex As Boolean

Set db = cnnemployee
Set tbldf = db.TableDefs("employees")


For Each idx In tbldf.Indexes
If idx = "emp" Then
empindex = True
End If

MsgBox idx.Name

Next idx


Set db = Nothing
Set tbldf = Nothing


End Function
 
Hi,

Which line is the error occuring on? - Look up debugging either on here or in the VB help files if you are unsure how to find out.
 
Also make sure that you have the correct references set for DAO.

Look under Tools>References. It'll be something like DAO 3.6

referenceswindow.png
 

Users who are viewing this thread

Back
Top Bottom