473,804 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form Field that Checks for Existing Primary Key Record & Add New Primary Key Record

2 New Member
Hi Folks,

I've got a problem that's been confounding me for months.

I work for a criminal court, and I'm trying to set up an Access database to track petitions filed by criminal defendants.

I am using the court's case file number record as the primary key to make sure the database doesn't wind up with multiple entries for the same case number.

However, a single case number can have other defendants charged in the same case number who can also file a petition.

As a result, I have a database tree that looks kind of like this:

Defendant#1 -- Petition -- FilingDate, etc.
/
CaseNumber
\
Defendant#2 -- Petition -- FilingDate, etc.

I have setup a table (Table: Case Number) that contains all the case number records, and it has a "one-to-many" relation to another table (Table: Petitions) that tracks each defendant's petition under each case number record. Remember that I'm using all the case number records as the primary key.

There are too many users and too many case numbers for any individual user to know whether or not a particular case number record has already been entered (as a primary key) into the Case Number Table.

So, when a user gets a new petition to enter into the system, I need a form that will do two actions:

1. Let the user enter in the petition's case number into a field that will check to see if there is a matching case number record in the Case Number Table. If there is, then it should bring up the associated record, and allow the user to add or update a petition.

AND

2. Let the user enter in the petition's case number into a field that will check to see if there is a matching case number record in the Case Number Table. If there is NOT a matching case number record, then it should allow the user to automatically add the case number as a new record in the Case Number Table. Then, it should allow the user to enter in the new petition.

I've got action #1 going just fine. My problem is getting action #2 to work. On all the forms I have created, whenever the user enters in a new case number record that IS NOT already a record in the Case Number Table, I get an error message that says: "You can't add or change a record because a related record is required in table 'Case Number'"

I'm relatively new to MS Access, and I'm definitely a newbie when it comes to programming in Visual Basic. So you may need to walk me through this using baby steps...

Thanks (in advance),
Neil (aka CourtGuy)
Apr 20 '07 #1
3 2842
MMcCarthy
14,534 Recognized Expert Moderator MVP
You need a main form for Case Numbers with petitions as a subform. That way you can choose an existing Case Number and add or edit petitions or add a new case number and then add petitions to it.
Apr 21 '07 #2
CourtGuy
2 New Member
Thanks mmcarthy,

I've tried setting it up as a subform, but it still gives the same error message.

I think I need some kind of code that checks to see if the Case Number record exists in the first table, and, if it doesn't, automatically add it to that first table and then allow the user to make entries in the Petitions table.
Apr 21 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Thanks mmcarthy,

I've tried setting it up as a subform, but it still gives the same error message.

I think I need some kind of code that checks to see if the Case Number record exists in the first table, and, if it doesn't, automatically add it to that first table and then allow the user to make entries in the Petitions table.
Have a form which opens prior to your main form and put the search on this instead. Behind your command button you could have something like the following:
Expand|Select|Wrap|Line Numbers
  1. Dim cNum As String
  2.  
  3.    cNum = nz(DLookup("[CaseNumber]", "TableName", "[CaseNumber]='" & Me!txtSearch & "'")," ")
  4.    If cNum = " " Then
  5.        DoCmd.OpenForm "FormName", , , , acFormAdd
  6.    Else
  7.        DoCmd.OpenForm "FormName", , , "[CaseNumber]='"  & Me!txtSearch & "'"
  8.    End If
  9.  
Mary
Apr 24 '07 #4

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

Similar topics

4
2731
by: Andy Proctor | last post by:
I hope there is an answer out there.... I have a simple database structured like this (non relevant tables and fields omitted) Members table memberID memberFname memberLname memberNokID
14
10147
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought I should give back to the community by posting our findings. Thanks you all for all your help till now by posting problems and their solutions. ~Abhijit
3
2605
by: Chris | last post by:
Before I started to create table, etc to track unique form field record number assigments I thought I'd check to see if there is now a better way to do this in .NET. I have a parent form (table) and children form (table). Relationship equals one to many. I'd like to auto number the fields accordingly and traditionaly I assign a unique number based on a table value that I retrieve + 1. i.e. Parent record field value = 1 Children record...
27
3960
by: Kim Webb | last post by:
I have a field on a form for project number. I basically want it to be the next available number (ie 06010 then 06011 etc). In the form I create a text box and under control source I put: =!= This does not work I tried:
4
8508
by: crystal | last post by:
I've checked the threads but haven't been able to come up with a solution to my issue. Help...... I have a simple form based on a table. Within the form is a subform that is also, through a Q, based on the same table. The code: Private Sub Select_BeforeUpdate(Cancel As Integer) On Error GoTo resetselect_Err
2
1949
by: Cerebral Believer | last post by:
Hi folks, Can anyone help me with this form: http://futurebydesign-music.com/_member/club_fbd_reg.php I have followed to coding instructions aas closely as I can, but I am getting errors about not filling in all the fields on the form correctly when I test it. Is validating a form with radio buttons difficult?
13
3439
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end of the form which is submit and cancel. After i have clicked submit, the information is stored directly into my corresponding database table. My problem here is i need to retrieve back the information submitted to display all the data that the...
17
3801
NeoPa
by: NeoPa | last post by:
I rarely use forms to manage my data so I expect this is easier than I found it (I hate it when OPs say that :D) I have a simple table (laid out below) with lists of customers for various jobs that have to be run. The PK is a combination of the first two fields ( & ) and I will typically want to maintain the various (logically separate) lists in different sessions (I may well use the same form design but only show one job at a time). For...
4
1415
by: GS | last post by:
in Windows form, I have Datagridview and detailview with the same binding data manager. upon clicking the + in the navigator, the primary key field is blank as expected, but I need to enable it for new record to let user to fill it. On the other hand I don't want to allow change to the field for existing record. so disable that on existing non new record. How do I do that? I notice the property of the fields are enabled in the form...
0
10595
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...
0
10343
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...
1
10335
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
10088
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
9169
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...
0
6862
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();...
0
5529
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
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
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.