473,763 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I erase a linked field of a record

Hello

I am working with Access 2000

I have two tables joined on a one to many relationship between two fields:
Table1:FieldID (one) is joined to Table2:FieldMyI D (many)

Field Properties setting:
FieldID : Field Size - Long Integer
New Values - Increment
Indexed - Yes (No Duplicates)
Data Type - AutoNumber

FieldMyID : Field Size - Long Integer
Default Value -
Required - No
Indexed - Yes (Duplicates OK)
Data Type - Number

When I add a record to Table2, FieldMyID must have a related record in
FieldID of Table1
However, Access 2000 will allow me to add a new record to Table2 without
having a related record in FieldID

of Table1 if I don't enter any data in FieldMyID (leave the FieldMyID
Null........... .. I think) and will allow me to open

Table2 and erase the content of FieldMyID manually.

Sometimes I need to erase the content of FieldMyID through codes and leave
the field blank but when I do that

I get an error message saying that a related record is required in Table1.

I have tried to set FieldMyID to Null, zero length string "" , and zero but
nothing seems to work.

Why is Access 2000 allowing me to leave FieldMyID empty on a new record or
erase the content of FieldMyID manually but not allowing me to erase the
content of FieldMyID through codes?

Could it be that when the content of a field is erased manually it is set to
something other than Null?

Thanks

G.Gerard


Nov 13 '05 #1
1 1946
You can programmaticall y set the foreign key field to Null, so there must be
another factor affecting your issue. Were you attempting to do that in a
multi-table recordset, rather than directly on the table?

This example sets the foreign key to null in the first record:
Function Set2Null()
Dim rs As DAO.Recordset
Set rs = DBEngine(0)(0). OpenRecordset(" SELECT * FROM Table2;")
rs.Edit
rs!FieldMyID = Null
rs.Update
rs.Close
Set rs = Nothing
End Function

If you want to set the foreign key field to Null when the main table record
is deleted, JET 4 supports a little known feature called "Cascade to Null".
It is not shown in the interface, and can be created with ADOX only.
Example:

Sub CreateKeyAdox()
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim ky As New ADOX.Key

Set cat.ActiveConne ction = CurrentProject. Connection
Set tbl = cat.Tables("tbl AdoxBooking")

'Create as foreign key to tblAdoxContract or.ContractorID
With ky
.Type = adKeyForeign
.Name = "tblAdoxContrac tortblAdoxBooki ng"
.RelatedTable = "tblAdoxContrac tor"
.Columns.Append "Contractor ID" 'Just one field.
.Columns("Contr actorID").Relat edColumn = "Contractor ID"
.DeleteRule = adRISetNull 'Cascade to Null on delete.
End With
tbl.Keys.Append ky

Set ky = Nothing
Set tbl = Nothing
Set cat = Nothing
Debug.Print "Key created."
End Sub

Of course, in the vast majority of relationships, the foreign key's Required
field should be set to Yes so you do not get orphaned records. Sometimes
they are helpful though.

--
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.

"GGerard" <gg*****@nbnet. nb.ca> wrote in message
news:%l******** *************@u rsa-nb00s0.nbnet.nb .ca...
Hello

I am working with Access 2000

I have two tables joined on a one to many relationship between two fields:
Table1:FieldID (one) is joined to Table2:FieldMyI D (many)

Field Properties setting:
FieldID : Field Size - Long Integer
New Values - Increment
Indexed - Yes (No Duplicates)
Data Type - AutoNumber

FieldMyID : Field Size - Long Integer
Default Value -
Required - No
Indexed - Yes (Duplicates OK)
Data Type - Number

When I add a record to Table2, FieldMyID must have a related record in
FieldID of Table1
However, Access 2000 will allow me to add a new record to Table2 without
having a related record in FieldID

of Table1 if I don't enter any data in FieldMyID (leave the FieldMyID
Null........... .. I think) and will allow me to open

Table2 and erase the content of FieldMyID manually.

Sometimes I need to erase the content of FieldMyID through codes and leave
the field blank but when I do that

I get an error message saying that a related record is required in Table1.

I have tried to set FieldMyID to Null, zero length string "" , and zero
but
nothing seems to work.

Why is Access 2000 allowing me to leave FieldMyID empty on a new record or
erase the content of FieldMyID manually but not allowing me to erase the
content of FieldMyID through codes?

Could it be that when the content of a field is erased manually it is set
to
something other than Null?

Nov 13 '05 #2

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

Similar topics

20
2695
by: Neil | last post by:
I have an Access 2000 MDB file with a SQL 7 back end. I have a main table with 50,000 records; and I have a selections table with 50,000 records for each machine that uses the database (about 25-50). This allows each user to have their own set of selections. The selections table has three fields: ID (int), Sel (bit), MachName (varchar). ID and MachName comprise the primary key. I have a view that combines the main table and the entries...
6
94553
by: Max | last post by:
Hi, I have SqlServer 2000 as back end and Access 2000 as front-end. All tables from Sqlserver are linked to Access 2000. I am having write conflict problem with one of my form which is bound to a query which consist of let say tableA , TableB and TableC (all are linked tables from SqlServer. While the form is open I am modifying TableA through code on Form_AfterUpdate Event and getting the following message.
1
3555
by: Smriti Dev | last post by:
Hi There, I hope you can help with this problem I have been having. I have linked tables from a mysql database and an access database. One of the fields (my primary key field) is an auto increment in mysql but once I link it to the access the auto increment field property is lost. This is the case with all the autoincrement fields that I have linked tables with. When I add a new record, I have to manually put in the autonumber field and...
8
9244
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record is entered, either from a form or from the table view of the table, when the record gets saved it immediately displays #DELETED# in all of the fields. However, if I close the form or table view and reopen the record has in fact been inserted. The...
2
4954
by: TJ | last post by:
I have a form that has a subform in it that links the Company_ID to the Shipper_ID. This works except when I want to let the user add a record. I then get a information message box saying that the record is suppose to have a value in it that matches the main form. Can I set the subform's link field with the master field in VBA? What I would like to do is something like this: Sub Click_Add()
1
4328
by: Julia | last post by:
Hello there. I have a question somewhat related to this topic, and I don't know where else to go. I hope somebody can help. I've created a database in access, that I'd like to share with less than 10 users. I'd like each user to see only some of the records in the database. So for example, if I have eight users in eight countries, I want each of them to only see information for their country. I was told that the easiest way to do...
22
18811
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is Access 2000 with the latest service pack of JET 4. The system is client/server, multiusers based. The MDBs are using record locking. Here is part of the code: Dim wkSpace As Workspace, db As Database Dim rstTrans As DAO.Recordset Set wkSpace = DBEngine.Workspaces(0)
3
2022
by: bjhecht | last post by:
http://rafb.net/paste/results/tJoB4z75.html After executing the following code I receive the errors: a.c: In function `insert': a.c:59: error: incompatible types in assignment I have no problem when first_name in the structure is an int. I can easily assign a default value in the insert function. But I would like to allow full strings to be sent to the field from the insert function....Any ideas?
9
4575
by: erick-flores | last post by:
If you have access to the database that the linked table is in, modify it there. You can't modify a linked table. Alternatively, you can import the linked table, then it won't be linked any more and you can modify it. There are potential problems with this strategy, as you will be working on a copy of the original table, so any new data that goes into the original table from elsewhere will not be reflected in your database. Hello all
0
9563
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
9386
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
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
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
7366
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
5270
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
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.