473,385 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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:FieldMyID (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 1909
You can programmatically 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.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables("tblAdoxBooking")

'Create as foreign key to tblAdoxContractor.ContractorID
With ky
.Type = adKeyForeign
.Name = "tblAdoxContractortblAdoxBooking"
.RelatedTable = "tblAdoxContractor"
.Columns.Append "ContractorID" 'Just one field.
.Columns("ContractorID").RelatedColumn = "ContractorID"
.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*********************@ursa-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:FieldMyID (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
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...
6
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...
1
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...
8
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...
2
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...
1
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...
22
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....
3
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...
9
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.