M. L. Tomson
M. L. Tomson

Reputation: 53

Linking two Independant MDB (access database) files, not tables

This is somewhat similar to a master-detail situation, with some variation.

Problem: I have two independant MS Access database files (.mdb), which need to be linked.

I couldn't find an appropriate master-detail linking method, mainly because the tablename has to change on the fly as cell data changes/updates in the grid.

So, I came up with an alternative linking method which is as follows. And I'm not entirely certain this is a good way to link them.

{DBGrid1 displays values from ADOTable1 } {DBGrid2 displays values from ADOTable2, which its tablename changes}

procedure TForm1.DBGrid1CellClick(Column: TColumn);
var PartTableName: string;
begin
if DBGrid1.Fields[2].IsNull then exit
  else
   begin
     if ADOTable2.active then ADOTable2.Close;
     PartTableName:= DBGrid1.Fields[2].AsString;
     while pos('-',TableString) > 0 do
       PartTableName[pos('-',PartTableName)] := '_';
     ADOTable2.TableName:= PartTableName;  //obtained from cell click in DBGrid1
     ADOTable2.Open;
   end;
end;

DBGrid2 displays the customers & products that use whatever part number, that is clicked on in DBGrid1.

There must be a better way of doing this? This way of linking seems crude to me. I'd also rather have this in the OnDataChange method, but doesn't seem to work.

Upvotes: 2

Views: 1395

Answers (3)

Warren  P
Warren P

Reputation: 68902

Instead of requerying, I would suggest you look into using ADO components to filter the content of the table. This would be roughly equivalent to a master-detail arrangement, and would have the advantage of only performing an "in memory" operation, and not hitting the db each time the "master" row changes. (On each master row change, just change the filter criteria on the child table)

Upvotes: 0

menjaraz
menjaraz

Reputation: 7575

TxQuery is another option for you.

Quote:

TxQuery component is a TDataSet descendant component that can be used to query one or more TDataSet descendant components using SQL statements.

Upvotes: 2

Toby Allen
Toby Allen

Reputation: 11213

You can set this up within Access. Thats a more robust solution than doing it in Delphi.

Find the Linked Table Manager in your version of Access and it allows you to link a table from another database into the one you have. Then you can access a single mdb with delphi and get at all the tables.

Upvotes: 3

Related Questions