473,396 Members | 2,002 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,396 software developers and data experts.

"related record is required in table . . ."

AccessIdiot
493 256MB
Argh! Just when I think everything is working and I am doing one final test before showing it to the guys I built the db for, Access throws out a weird message and won't let me add a record. But only SOMETIMES.

I am getting "You cannot add or change a record because a related record is required in table "tbl_Entrianment". The only thing that relates the two tables in question is the Entrainment_ID WHICH I CAN SEE ON MY FORM.

Let me back up.

I have a form/table Entrainment. An Entrainment can have lots of Specimens (one to many with Entrainment_ID; autonumber/primary key in tbl_Entrainment and number/foreign key in tbl_Specimen_Entrainment). On my Entrainment form is a button to view/add Specimens. It launches a filtered Specimen_Entrainment form (where Entrainment_ID of the Entrainment form = the Entrainment_ID of the Specimen form). I can add new records to the Specimen form no problem.

However, I have a "not in list" function on the Species control of the Specimen_Entrainment form. After I add a new Species and return to the Specimen_Entrainment form I get the error message. Here is the code for the not in list:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Species_ID_NotInList(NewData As String, Response As Integer) 
  2. Dim Result
  3. Dim Msg As String
  4. Dim CR As String
  5.  
  6.     CR = vbCr
  7.  
  8.     ' Exit this subroutine if the combo box was cleared.
  9.     If NewData = "" Then Exit Sub
  10.  
  11.     ' Ask the user if he or she wishes to add the new customer.
  12.     Msg = "'" & NewData & "' is not in the list." & CR & CR
  13.     Msg = Msg & "Do you want to add it?"
  14.     If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
  15.        ' If the user chose Yes, start the Species form in data entry
  16.        ' mode as a dialog form, passing the new species code name in
  17.        ' NewData to the OpenForm method's OpenArgs argument. The
  18.        ' OpenArgs argument is used in Species form's Form_Load event
  19.        ' procedure.
  20.        DoCmd.OpenForm "frm_Species_Freshwater", , , , acFormAdd, acDialog, NewData
  21.     End If
  22.  
  23.     ' Look for the species code name the user created in the Specimen form.
  24.     Result = DLookup("[Species_Code]", "tbl_Species_Freshwater", _
  25.              "[Species_Code]='" & NewData & "'")
  26.     If IsNull(Result) Then
  27.        ' If the species code was not created, set the Response argument
  28.        ' to suppress an error message and undo changes.
  29.        Response = acDataErrContinue
  30.        ' Display a customized message.
  31.        MsgBox "Please try again!"
  32.     Else
  33.        ' If the species code was created, set the Response argument to
  34.        ' indicate that new data is being added.
  35.        Response = acDataErrAdded
  36.     End If
  37.  
  38. End Sub
The thing is, I can add the new species, but when I close the frm_Species_Freshwater form to continue entering data on the Specimen_Entrainment form that's when I get the error message. I can see the correct Entrainment_ID on the Specimen_Entrainment form so I'm not sure why it's giving me the error message?
Apr 30 '07 #1
5 4983
AccessIdiot
493 256MB
I should also add that if I go ahead and change the species to something else (it is a combo box on the Specimen_Entrainment form), something that already existed before, I still get the error message. It's like, once I add something to the Species table through the not in list function it doesn't want to continue in any way.
Apr 30 '07 #2
Rabbit
12,516 Expert Mod 8TB
Toss in a save command before opening the form. I've come across this where the record with the primary key hasn't been updated to the table before trying to add a foreign key record.
Apr 30 '07 #3
AccessIdiot
493 256MB
Hey Rabbit which form do you mean? Do you mean after a new species is added to the list before returning to the Specimen_Entrainment form?
Apr 30 '07 #4
AccessIdiot
493 256MB
You are a freaking genius, thank you!
Apr 30 '07 #5
Rabbit
12,516 Expert Mod 8TB
You are a freaking genius, thank you!
If only. Experience more than anything.
Apr 30 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gary N | last post by:
Sr. Database Administrator Permanent Position/Pittsburgh Pa $70-95K with full benefits Description A client of A.C.Coy's is looking for a Senior Database Administrator to join their team on a...
0
by: Hanuman | last post by:
Hi, On the IBM host we use a product called RDX that lets us copy "related" table data from the QA and prod environments to our UT environments. For example if we provide a CustomerID as input...
0
by: elvin | last post by:
Okay - apologize in advance for the length, but I want to make sure all you knowledgeable and helpful people have all the details you need to hopefully point my newbie rear in the right direction....
1
by: Just Me | last post by:
Table A contains a list of colors (example red, blue, green) Table B contains a variation of the colors in Table A (example light-red, medium-red, dark-red) To add a color variation to Table...
1
by: me | last post by:
I'm building a multi user app where many admins will be making calls to people in one table. I want to keep things simple and find a way to prevent 2 or more admins from working on the same record...
0
by: Gawn | last post by:
Dear all, Greeding from Thailand. Need help for my news script. I am trying to display news which keywords match the current page keywords. I am using Dreamweaver 8 and PhpMyAdmin to manage MySQL....
12
by: jpatchak | last post by:
Hello all, I have an annoying message popping up every time I close a form. Due to performance issues, I am caching data from a linked table on a SQL Server into a temporary local table. The...
5
by: dougmeece | last post by:
I have two forms with one calling the other to perform searches. When I run the search form the 2nd form a blank record is added to my table. The table is appended or updated from entries on the...
25
by: tekctrl | last post by:
Anyone: I have a simple MSAccess DB which was created from an old ASCII flatfile. It works fine except for something that just started happening. I'll enter info in a record, save the record,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.