PC Review


Reply
Thread Tools Rate Thread

Creating Index in Exported Table

 
 
Dkline
Guest
Posts: n/a
 
      10th Jun 2004
I am exporting by VBA many queries in one database to another database as
tables. These tables do not appear to inherit the indexes - presumably
because I'm exporting a query to become a table.

I've been trying to figure out how to create an index through VBA or even a
macro.

I'm certain I just need to set the field's "Indexed" property but I can't
find anything in the object browser to use.


 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      10th Jun 2004
This example shows how to programmatically create a primary key index, a
single field index, and a multi-field index using the DAO library:

Sub CreateIndexDAO()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim ind As DAO.Index

'Initialize
Set db = CurrentDb()
Set tdf = db.TableDefs("MyTable")

'1. Primary key index.
Set ind = tdf.CreateIndex("PrimaryKey")
With ind
.Fields.Append .CreateField("ID")
.Primary = True
End With
tdf.Indexes.Append ind

'2. Single-field index.
Set ind = tdf.CreateIndex("MyField")
ind.Fields.Append ind.CreateField("MyField")
tdf.Indexes.Append ind

'3. Multi-field index.
Set ind = tdf.CreateIndex("FullName")
With ind
.Fields.Append .CreateField("Surname")
.Fields.Append .CreateField("FirstName")
End With
tdf.Indexes.Append ind

'Refresh the display of this collection.
tdf.Indexes.Refresh

'Clean up
Set ind = Nothing
Set tdf = Nothing
Set db = Nothing
End Sub

--
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.

"Dkline" <(E-Mail Removed)> wrote in message
news:%232yK%(E-Mail Removed)...
> I am exporting by VBA many queries in one database to another database as
> tables. These tables do not appear to inherit the indexes - presumably
> because I'm exporting a query to become a table.
>
> I've been trying to figure out how to create an index through VBA or even

a
> macro.
>
> I'm certain I just need to set the field's "Indexed" property but I can't
> find anything in the object browser to use.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Not Running in Exported Pivot Table =?Utf-8?B?RGF2aWQxMjc=?= Microsoft Excel Programming 2 10th Mar 2007 10:44 PM
Repair Database Error -- 'AO Index' is not an index in this table =?Utf-8?B?Sm9uTXVsZGVy?= Microsoft Access 7 8th Sep 2006 07:54 PM
Creating an Index Table =?Utf-8?B?SGFt?= Microsoft Access Getting Started 5 19th Nov 2004 02:33 AM
Retrieving data table index for datagrid index selected Dvae c Microsoft Dot NET Compact Framework 2 5th Oct 2003 01:43 PM
Access Denied creating exported NT4 object on Win2K Chris Warr Microsoft Dot NET 0 24th Sep 2003 01:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:55 PM.