Solved

Changing the table name in access by code?

Posted on 2006-06-23
3
160 Views
Last Modified: 2010-04-04
Hello Guys,

I have a system that uses access database, this system is over 1.000 computer and it is impossible to me change the access databases in each computer, so I need to make a exe to update the database, this patch will be in internet do be downloaded. My question is:

How can I change my table name by code ? the database is access.

Thanks
0
Comment
Question by:hidrau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Assisted Solution

by:atul_parmar
atul_parmar earned 250 total points
ID: 16968755
Hi,

Import the DAO type library (DAO_TLB.PAS), add it to your uses list then paste the following code.

var
  FEngine, FDB : OleVariant;
begin
  FEngine := CoDBEngine.Create;
  FDB := FEngine.OpenDatabase('c:\db1.mdb');
  FDB.TableDefs['Table1'].Name := 'NewName';
  FDB.Close;
  FDB := Unassigned;
  FEngine := Unassigned;
end;
0
 
LVL 11

Accepted Solution

by:
calinutz earned 250 total points
ID: 16969392
Or without type libraryes... just do it the natural way... create a new table with the new name with the same field structure and then insert into newtable select * from oldtable... Something like this:

AdoQuery1.Active:=false;
 AdoQuery1.SQL.Clear;
 AdoQuery1.SQL.Add('create table NewTABLE (FirstField varchar(30),SecondField varchar(20), 3rdField int)';//Keep the same structure as in the old table
 AdoQuery1.ExecSQL;

 AdoQuery1.Active:=false;
 AdoQuery1.Sql.Clear;
 AdoQuery1.SQL.Add('insert into NewTABLE Select * from OldTABLE); // copy the contents of old table in the new one
 AdoQuery1.ExecSQL;

 AdoQuery1.Active:=false;
 AdoQuery1.Sql.Clear;
 AdoQuery1.SQL.Text:= 'drop table OldTABLE'; //delete the old table
 AdoQuery1.ExecSQL;


And there you go...
0
 
LVL 1

Author Comment

by:hidrau
ID: 16971130
thanks very much
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question