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_Entrianmen t". 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_En trainment). On my Entrainment form is a button to view/add Specimens. It launches a filtered Specimen_Entrai nment 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_Entrai nment form. After I add a new Species and return to the Specimen_Entrai nment form I get the error message. Here is the code for the not in list: - Private Sub Species_ID_NotInList(NewData As String, Response As Integer)
-
Dim Result
-
Dim Msg As String
-
Dim CR As String
-
-
CR = vbCr
-
-
' Exit this subroutine if the combo box was cleared.
-
If NewData = "" Then Exit Sub
-
-
' Ask the user if he or she wishes to add the new customer.
-
Msg = "'" & NewData & "' is not in the list." & CR & CR
-
Msg = Msg & "Do you want to add it?"
-
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
-
' If the user chose Yes, start the Species form in data entry
-
' mode as a dialog form, passing the new species code name in
-
' NewData to the OpenForm method's OpenArgs argument. The
-
' OpenArgs argument is used in Species form's Form_Load event
-
' procedure.
-
DoCmd.OpenForm "frm_Species_Freshwater", , , , acFormAdd, acDialog, NewData
-
End If
-
-
' Look for the species code name the user created in the Specimen form.
-
Result = DLookup("[Species_Code]", "tbl_Species_Freshwater", _
-
"[Species_Code]='" & NewData & "'")
-
If IsNull(Result) Then
-
' If the species code was not created, set the Response argument
-
' to suppress an error message and undo changes.
-
Response = acDataErrContinue
-
' Display a customized message.
-
MsgBox "Please try again!"
-
Else
-
' If the species code was created, set the Response argument to
-
' indicate that new data is being added.
-
Response = acDataErrAdded
-
End If
-
-
End Sub
The thing is, I can add the new species, but when I close the frm_Species_Fre shwater form to continue entering data on the Specimen_Entrai nment form that's when I get the error message. I can see the correct Entrainment_ID on the Specimen_Entrai nment form so I'm not sure why it's giving me the error message?
5 4999
I should also add that if I go ahead and change the species to something else (it is a combo box on the Specimen_Entrai nment 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.
Rabbit 12,516
Recognized Expert Moderator MVP
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.
Hey Rabbit which form do you mean? Do you mean after a new species is added to the list before returning to the Specimen_Entrai nment form?
You are a freaking genius, thank you!
Rabbit 12,516
Recognized Expert Moderator MVP
You are a freaking genius, thank you!
If only. Experience more than anything.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 permanent basis in Pittsburgh PA.
Requirements
Bachelor's degree, or equivalent experience in computer science or
|
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 it will retrieve
related tables like CustTransaction and CustHistory and so on (so long
as the relations are defined to RDX)
Is there a way to use the output of this RDX to load the UDB tables on
the LAN? Is there another product that will do...
|
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.
I've got a fairly complex (a lot more complex than originally
intended) database with three main tables. The database is designed
to track information about certain files. The tables are set up with
one to one relationships, primarily because...
|
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 B, I want it to open a find record
dialog box before it opens the form so that you can locate the main
color you are going to enter the variations for. The form should then
open with the information from Table A already preloaded (or a dialog
box...
|
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 at the same time. In other
words I need a way to go the next "available" record. Any help will be
greatly appreciated, please reply here in the NG. Thanks in advance !!
| |
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. May I explain you what I have done. My database and data in that look like this.
//* Data Base
-- phpMyAdmin SQL Dump
-- version 2.6.2-pl1
-- http://www.phpmyadmin.net
--
|
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 user makes changes to data that are stored in the local table. Then, when the user closes the form, I run a couple of quick queries to update the data back on the server and delete any data in the temp table. After the code runs in the Close event of...
|
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 first form but the second form doesn’t reference the table at all. The queries ran from the form obviously query the table for data but these are not the same queries that update/append.
Any ideas what would cause this to happen?
As always,...
|
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, and try to move to another record and get
an Access error "Record is too large". The record is only half filled, with
many empty fields. If I remove the added data or delete some older data,
then it saves ok and works fine again. Whenever I'm...
|
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,...
|
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...
| |
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |