Re: Make column indexed



Brian Hollister wrote:
try here to, you'll probably need to find the right version for yourself:

http://msdn2.microsoft.com/en-us/office/aa905400.aspx

Thanks Brian -
I didn't know about the VBA help file. Took a while to find it. I don't speak enough VBA to be able to get enough from it.

M$ makes me crazy with their code examples that do not match the prototypes.

Between the MSDN site you referenced (and some more Googling), this works:

procedure TForm1.Button1Click(Sender: TObject);
var
sql: string;
cat: ADOX_TLB._Catalog;
col : ADOX_TLB._Column;
table : ADOX_TLB._Table;
ndx: ADOX_TLB._Index;
Connection: ADODB_TLB._Connection;
fName: olevariant;
begin
Connection := adodb_tlb.CoConnection.Create;
Connection.ConnectionString := DataSource;
//Get exclusive access to modify the database's structure. Default adModeUnknown.
Connection.Mode := adModeShareExclusive;
Connection.Open('', '', '', 0); //unassigned
Cat := CoCatalog.Create;
// Link the Catalog object to the open connection
Cat._Set_ActiveConnection(Connection);
fname := 'RecID';
table := Cat.Tables['Log'];
label1.Refresh;
col := CoColumn.Create ;
//col.Properties
with col do
begin
ParentCatalog := cat;
Name := fName;
Type_ := adInteger;
Properties['AutoIncrement'].Value := true;
table.Columns.Append(col, Unassigned, Unassigned);
end;
ndx := Adox_tlb.CoIndex.Create; // This one was a bear!
ndx.Name := 'RecIDx';
ndx.IndexNulls := adIndexNullsDisallow;
//ndx.Unique := true; //does nothing to prevent duplicates
table.Keys.Append('RID', adKeyUnique, 'RecID','Log','RecID'); //Prevent duplicates
ndx.Columns.Append('RecIDx',adInteger,0);
table.Indexes.Append('RecIDx', 'RecID');
end;
.


Quantcast