Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2006, 12:50 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default setting autoincrement

I'm having some trouble setting the autoincrement field attached to a newly created Aceess table field. I'm using Delphi 7.

Code

  strRangeDB := FMapDir + strRange + '\Database\RangeData.MDB';
  strConn := Format('Provider=''Microsoft.Jet.OLEDB.4.0'';Data
                      Source=''%s'';',[strRangeDB]);

  // Open Catalog for Range Database
  try
    oCatalog := CoCatalog.Create();
  except
    EventLog.LogEvent('ADOX is not installed!');
    raise Exception.Create('ADOX is not installed!');
  end;

  try
    oCatalog.Set_ActiveConnection(strConn);
  except
    EventLog.LogEventFmt('Unable to connect to %s',[strRangeDB]);
    Exit;
  end;

  try
    oTable2 := oCatalog.Tables.Item['tblShape'];
  except
    IsUpdated := TRUE;
    oTable2 := CoTable.Create;
    oTable2.Name := 'tblShape';
    oTable2.ParentCatalog := oCatalog;

    with oTable2 do
    begin
      oCol := CoColumn.Create;
      oCol.Name := 'ID';
      oCol.type_ := adGUID;
      oCol.DefinedSize := 0;
      oCol.ParentCatalog := oCatalog;
      Columns.Append(oCol, adGUID, 0);
      oCol.Properties.Item['AutoIncrement'].value := TRUE;
   end;
   oCatalog.Tables.Append(oTable2);
 end;

I'm getting " Format "%d" invalid or imcompatible with argument " on the line in red. What is really strange is that if I move the append
call above the line where the autoincrement is set to true, I get this same error but on the line where autoincrement is set to true. I'm somewhat new to ADOX and COM in general so any help would appreciated.





 
Old June 20th, 2006, 12:53 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Few people will know less about Delphi than me, but the approach you would take from VBA is to not even reference the autonumber field and let Access take care of it by itself. Not sure if that will work in this situation, but it's worth a try.

Mike

Mike
EchoVue.com
 
Old June 20th, 2006, 01:10 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply.

But the autoincrement property has to be set otherwise the field type is just a regular number field.

On another note, I've read threw a few forums and looked at MSDN and followed the examples they had. All of them were in VB. But i still get that format error even when my code follows the same logic as the examples, so I'm guessing it has something to do with Delphi but i cant be sure.

 
Old June 20th, 2006, 01:17 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Sorry my bad! I was thinking you were inserting data, not creating the table itself. I should probably have had more sleep last night.

My only other thought would be that the actual term might be something different like AutoNumber instead of AutoIncrement, or something like that. But that is probably what you were getting at to begin with.

Anyone else have any ideas?

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
dataset and autoincrement primary key be03024 ADO.NET 8 July 19th, 2009 12:09 PM
AutoIncrement Aaron Edwards ASP.NET 2.0 Basics 5 February 7th, 2007 02:37 PM
PrimaryKeys, AutoIncrement gbilios VB.NET 2002/2003 Basics 4 June 9th, 2005 07:31 AM
Generated dataset and autoincrement dbradley ADO.NET 5 February 2nd, 2005 01:14 AM
Autoincrement field not incrementing leo_vinay SQL Server ASP 1 January 4th, 2005 08:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.