473,671 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

relations

Hi everyone

Is there someone out there who can tell me how to create relationships
between tables using VB???
PS I am using MS ACCESS 2003 and I have read the help...
THANK YOU
Nov 12 '05 #1
1 2046
This example assumes a main table named "tblContrac tor" with primary key
"Contractor ID", and a related table "tblBooking " with a foreign key named
"Contractor ID". The result is that one contractor can have many bookings.

Sub CreateRelationD AO()
Dim db As DAO.Database
Dim rel As DAO.Relation
Dim fld As DAO.Field

'Initialize
Set db = CurrentDb()

'Create a new relation.
Set rel = db.CreateRelati on("tblContract ortblBooking")

'Define its properties.
With rel
'Specify the primary table.
.Table = "tblContrac tor"
'Specify the related table.
.ForeignTable = "tblBooking "
'Specify attributes for cascading updates and deletes.
.Attributes = dbRelationUpdat eCascade + dbRelationDelet eCascade

'Add the fields to the relation.
'Field name in primary table.
Set fld = .CreateField("C ontractorID")
'Field name in related table.
fld.ForeignName = "Contractor ID"
'Append the field.
.Fields.Append fld

'Repeat for other fields if a multi-field relation.

End With

'Save the newly defined relation to the Relations collection.
db.Relations.Ap pend rel

'Clean up
Set fld = Nothing
Set rel = Nothing
Set db = Nothing
Debug.Print "Relation created."
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"nicolaas" <go****@ngaru.c om> wrote in message
news:28******** *************** **@posting.goog le.com...
Hi everyone

Is there someone out there who can tell me how to create relationships
between tables using VB???
PS I am using MS ACCESS 2003 and I have read the help...
THANK YOU

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2988
by: Bose | last post by:
Hi I have to make export of SQL Server Database to MS Access and I have done it with the tables but now I need to transfer(export) the relations, keys and indexes. Can any1 tell me how to read relations,keys and indexes from SQL Server and convert them to MS Access.(it seams that for creation of indexes in MS Access ADOX is the only way but ADOX cannot read all information about keys,indexes from SQL Server.) All I can see is that I have...
2
945
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
1
1569
by: Iain | last post by:
I've a fairly complex schema which I'm trying to create a typed data set for. I've had a number of issues to date but it is sort of working (e.g. elements are not considered nullable unless minOccurs="0" is present. If not the codegen:nullValue attribute is ignored). What I'm seeing at the moment is that if I do NOT add in key and key ref relations, the cs generated puts in sensibly named relations with appropriate accessors. But...
1
1798
by: Jef De Rycke | last post by:
Hi access group, I have written code to create relations between tables according to a corresponding relations information table. At first I thought my code was not working properly because after running the code the relations don't show in the relations window. However when I enter data in an underlying table I get referential integrity error messages so the relations does actually exist. The created relations do show in the relations...
10
1872
by: D | last post by:
hi I have a form with 2 datagrids showing related table data in a master / child or order / order details type relationship. I would like to auto select the row in the order details table which contains the highest priced item. My thoughts were to get the currency manager from the orderdetails table and iterate thru each row and keep track of the highest item and row and select that when done. I have found that for some reason the...
0
1183
by: Joe Van Meer | last post by:
Hi all, I have a question regarding data relations within a data set. Say I have 3 tables named CLIENT, BOOKING and EMPLOYEE and I wanted to relate the first two tables (CLIENT AND BOOKING) via a clientid and relate the second set of tables (BOOKING AND EMPLOYEE) using an employeeid. My problem arises when there a re no records in one of the tables in either data relation. What is the best way to handle this, check the number of...
1
5126
by: Randy Fraser | last post by:
How do I create a relationship on muliple columns in an untyped dataset. Why does this not work. da.Fill(ds) ds.Tables(0).TableName = "DesignSummary" ds.Tables(1).TableName = "FormulaSummary" ds.Tables(2).TableName = "MaterialSummary" ds.Tables(3).TableName = "ItemUsage" ds.Tables(5).TableName = "UsageSummary"
2
2868
by: Joe | last post by:
Hi I have a dataset with 3 tables and 2 relations Is there a way to when I am at 1 row to tell if there is a relation on that row ??? I have the code hardcoded but try to make it work if the # of tables and #relations increase or decrease So I can just pass any dataset and walk thru the rows?? Thanks
2
2488
by: Joe | last post by:
Hi I am going to receive a dataset downstream and I will not know the the fields number of field relations number of relations So I have to be flexible to take unknown data and be able to summarize all the info being passed
5
3103
by: G .Net | last post by:
Hi I'm hoping that somebody can help me with a fairly puzzling problem. I've created some DataTables which have relations between them e.g. one to many. In the application, I want to remove entries from the table. To do this I obviously need to temporarily switch off the relations. In order to achieve this, I tried: ds.Relations.Clear() ' where ds is the application DataSet
0
8483
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8402
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8927
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8676
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6237
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.