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

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

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 2817
MMcCarthy
14,534 Expert Mod 8TB
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
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 Expert Mod 8TB
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
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
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...
3
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)...
27
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: =!=...
4
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,...
2
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...
13
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...
17
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...
4
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.