Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
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 September 18th, 2004, 03:48 AM
Registered User
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Access database at runtime

Look at the following code:

// catalog object
Catalog cat = new CatalogClass();

// naslov
Table dtNaslov = new TableClass();
dtNaslov.Name = "Naslov";
dtNaslov.Columns.Append("ID_Naslov",DataTypeEnum.a dInteger,4);
dtNaslov.Keys.Append("ID_Naslov",KeyTypeEnum.adKey Primary,"ID_Naslov","Naslov","ID_Naslov");
dtNaslov.Columns.Append("Ulica",DataTypeEnum.adVar WChar,50);
dtNaslov.Columns.Append("PostnaSt",DataTypeEnum.ad SmallInt,4);
dtNaslov.Columns.Append("Kraj",DataTypeEnum.adVarW Char,50);

// potnik
Table dtPotnik = new TableClass();
dtPotnik.Name = "Potnik";
dtPotnik.Columns.Append("ID_Potnik",DataTypeEnum.a dInteger,4);
dtPotnik.Keys.Append("ID_Potnik",KeyTypeEnum.adKey Primary,"ID_Potnik","Potnik","ID_Potnik");
dtPotnik.Columns.Append("ID_Naslov",DataTypeEnum.a dInteger,4);
dtPotnik.Keys.Append("ID_Naslov",KeyTypeEnum.adKey Foreign,"ID_Naslov","Naslov","ID_Naslov");
dtPotnik.Columns.Append("Ime",DataTypeEnum.adVarWC har,50);
dtPotnik.Columns.Append("Priimek",DataTypeEnum.adV arWChar,50);

// partner
Table dtPartner = new TableClass();
dtPartner.Name = "Partner";
dtPartner.Columns.Append("ID_Partner",DataTypeEnum .adInteger,4);
dtPartner.Keys.Append("ID_Partner",KeyTypeEnum.adK eyPrimary,"ID_Partner","Partner","ID_Partner");
dtPartner.Columns.Append("ID_Naslov",DataTypeEnum. adInteger,4);
dtPartner.Keys.Append("ID_Naslov",KeyTypeEnum.adKe yForeign,"ID_Naslov","Naslov","ID_Naslov");
dtPartner.Columns.Append("Naziv",DataTypeEnum.adVa rWChar,100);

A problem is, when debug mode is trying to do cat.Tables.Append((object)dtPartner). It
throws an exception: "ID_Naslov object already exist". Why is that? I only want to
create a relationship between Naslov & Potnik tables and Naslov & Partner tables.
How can I create a Foreign key in table Partner? It generates Foreign key in table
Potnik perfectly, but in Partner table it throws an exception.
Can someone please help?

Oh, how can I add an AutoNumber field to the ID_Naslov? Thanks

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating login form with access database Belzebu Visual Basic 2005 Basics 0 November 8th, 2007 11:33 AM
Creating CheckBox at runtime. sachingowdar Java GUI 2 April 22nd, 2007 09:55 PM
Creating a DLL at runtime jai2k Beginning VB 6 1 January 5th, 2005 01:23 PM
Creating Access database at runtime in C# janigorse General .NET 0 September 18th, 2004 06:24 AM
creating access runtime versions Loralee Access VBA 7 September 2nd, 2004 10:26 PM

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