Board index » delphi » Help MSAccess CreateTable

Help MSAccess CreateTable

Hi ,
I have a problem creating new table in .mdb
I create empty .mdb file using DAO and then trying to create Table as it
showun in Delphi Online help
I change 'ttParadox' to 'ttDefault' and use Tdatabase component with
DriverName 'MSACCESS'
Then conect TTable component to this TDataBase component. Then I do the
things from delphi help - 'create table'.
 Everiting is fine compiles and execute but there are not new table in my
database.
What are am doing  wrong?
Thanks
 

Re:Help MSAccess CreateTable


Are you using the TTable.Create table method or the SQL CREATE TABLE
statement in a TQuery? Show us the code.

--
Bill Todd (TeamB)
(Questions received via email cannot be answered.)

Re:Help MSAccess CreateTable


Quote
>What are am doing  wrong?

You are probably asking Access to create a table with some feature it doesn't
support.   But you are not giving use any example to go buy so this is just a
guess.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Help MSAccess CreateTable


Thanks.

I solved the problem. I created new alias  in run time using MSACCESS driver
and then it works OK.

Regards

"Brian Bushay TeamB" <BBus...@Nmpls.com> wrote in message
news:39b87ef8.38164146@forums.Inprise.com...

Quote

> >What are am doing  wrong?

> You are probably asking Access to create a table with some feature it
doesn't
> support.   But you are not giving use any example to go buy so this is
just a
> guess.

> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:Help MSAccess CreateTable


Hey everybody
Thanks for  tips, very usfull!
I have just create this table in DAO.I am not decieded yet whch way I am
going to use.(BDE or DAO)
May be with becouse I want to add some relations when create database so may
be usefull for others it is a way to create Table using DAO.
I am working with Access 97.

procedure TAccUtil.CreateParameterTable(DBName:String);
var
  tdf,
  fld1,fld2,fld3,fld4,
  DBEngine,Workspace,db: Variant;

begin
   try
    DBEngine := CreateOleObject('DAO.DBEngine.35');
    Workspace := DBEngine.Workspaces[0];
    {Open database}
   db:=DBEngine.WorkSpaces[0].OpenDatabase(DBName,True);
except on E: EOleException do
   ShowMessage('Could not create ' + E.Message);
  end;

  {Create('ParameterProducts' table)}
  tdf:=db.CreateTableDef('ParameterTable');  {flexibilities would be good}
  {TFieldType 7-> Double, 4-> LongInteger in MSAccess}
  fld1:=tdf.CreateField('Scale',TFieldType(7));
  fld2:=tdf.CreateField('Radius',TFieldType(7));
  fld3:=tdf.CreateField('WarehouseFix',TFieldType(7));
  tdf.Fields.Append(fld1);
  tdf.Fields.Append(fld2);
  tdf.Fields.Append(fld3);
  tdf.Fields.Append(fld4);

  try{raized exception}
  db.TableDefs.Append(tdf);
  except
  if MessageDlg('The Table alredy exist.'+ #13+'Yes to rewrite, All to
append!',
    mtConfirmation, [mbYes, mbAll], 0) = 6 then
    begin
     db.TableDefs.Delete('ParameterTable');
     db.TableDefs.Append(tdf);
    end;
  end;
end;

Re:Help MSAccess CreateTable


Quote
"Angel" <angel.fi...@bjy.com> wrote in message news:39ad5bd6_1@dnews...

[...]

Quote
>   {Create('ParameterProducts' table)}
>   tdf:=db.CreateTableDef('ParameterTable');  {flexibilities would be good}

What do you mean by flexibilities?  Do you mean tabledef properties?  You
can set them like this:

  tdf.properties['some property name'].value := <some value>;
Note that you must use the fully expanded syntax or else you'll get a
compiler error about trying to write to a read-only property.

Quote
>   {TFieldType 7-> Double, 4-> LongInteger in MSAccess}
>   fld1:=tdf.CreateField('Scale',TFieldType(7));

It's better to use the DataTypeEnum constants:

fld1:=tdf.CreateField('Scale',dbDouble);

BTW, if you declare your variables as DAO objects instead of variants Code
Insight works properly.  IOW, declare:

var
  DBE: DBEngine;
  Wks: Workspace;
  DB: Database;
  Tdf: TableDef;
  Idx: Index;
  Fld: Field;

--

"Relationships are hard. It's like a full-time job, and we should treat it
like one. If your boyfriend or girlfriend wants to leave you, they should
give you two weeks' notice. There should be severance pay, and before they
leave you, they should have to find you a temp."
Bob Ettinger

Other Threads