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

How do I prevent records from being created in a related table?

Hello,

I have been successfully using a database I've created for several months to populate an equipment list for a project we've been working on. However, the form has recently stopped working for some unknown reason. I've been having a problem recently where one table (Project Info) keeps auto-incrementing when I try to create a new record with another table (Equipment Info). Only the Equipment table is supposed to grow. It used to never grow the project table, but now it is and I'm stumped as to what is causing it.

Here are the details of my tables:

Table 1: Project Info
-Supposed to only hold one record (a static table)
-ProjKey=1 (integer, primary key)... Required=No, Indexed=Yes (No duplicates)
-Holds misc. project information such as project title, job #, etc.
-Holds project specific information for equipment
-Users can edit project information in a separate form (which works fine)

Table 2: Equipment List Data
-Holds many records and can increase in records (a dynamic table)
-Holds misc. information about the equipment
-ItemNo=* (integer, primary key... grows through a form macro when user enters a new record, which has worked fine in the past)... Required=No, Indexed=Yes (No duplicates)
-ProjLink=1 (integer)... Default Value=1, Required=No, Indexed=No

Here is the details of my query:
-Equipment table ProjLink has 1 to 1 relationship with Project table ProjKey
-Shows all equipment fields
-Shows specific project related info from the project table related to the equipment (this should be static)

Here are a handful of the details of my form:
-Allow Filters = Yes, Allow Edits = Yes, Allow Deletions = Yes, Allow Additions = Yes, Data Entry = No, Recordset Type = Dynaset, Record Locks = No locks, Fetch Defaults = Yes
-The macro that increments ItemNo for the equipment executes on "Got Focus". The code is below...

Private Sub ItemNoBox_GotFocus()
Dim strMsg As String
If Me!ItemNoBox.Value > 0 Then
Exit Sub 'we don't want to run this if something already exists
End If
Call incrNumber(Me, strMsg, "ItemNoBox")
If strMsg <> vbNullString Then
MsgBox strMsg, vbInformation
End If
End Sub

-incrNumber uses recordset clone to see what the itemNo was for the last record, then increments it. This was done to circumvent the problem[autonumber] had with incrementing whenever a user hits "Esc" to cancel input into a form, or when a record must be deleted for whatever reason. Since autonumbers cannot be edited, I had to code it this way.

In the form, upon creating a new equipment, I then get the following message:
"The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again." I put a box that shows the ProjKey, and it has been changing when it shouldn't.

When I create records using the query, it does not have this problem. How can I fix my form? Or, how can I force my project table to never grow?

Thank you.
Feb 22 '08 #1
4 2137
FishVal
2,653 Expert 2GB
Hello,

I have been successfully using a database I've created for several months to populate an equipment list for a project we've been working on. However, the form has recently stopped working for some unknown reason. I've been having a problem recently where one table (Project Info) keeps auto-incrementing when I try to create a new record with another table (Equipment Info). Only the Equipment table is supposed to grow. It used to never grow the project table, but now it is and I'm stumped as to what is causing it.

Here are the details of my tables:

Table 1: Project Info
-Supposed to only hold one record (a static table)
-ProjKey=1 (integer, primary key)... Required=No, Indexed=Yes (No duplicates)
-Holds misc. project information such as project title, job #, etc.
-Holds project specific information for equipment
-Users can edit project information in a separate form (which works fine)

Table 2: Equipment List Data
-Holds many records and can increase in records (a dynamic table)
-Holds misc. information about the equipment
-ItemNo=* (integer, primary key... grows through a form macro when user enters a new record, which has worked fine in the past)... Required=No, Indexed=Yes (No duplicates)
-ProjLink=1 (integer)... Default Value=1, Required=No, Indexed=No

Here is the details of my query:
-Equipment table ProjLink has 1 to 1 relationship with Project table ProjKey
-Shows all equipment fields
-Shows specific project related info from the project table related to the equipment (this should be static)
Could you be more specific here?
What is [ProjLink] table? Is it a bridge table to implement many-to-many relationship betweeen two tables mentioned above? Why relationship is 1 to 1?

Private Sub ItemNoBox_GotFocus()
Dim strMsg As String
If Me!ItemNoBox.Value > 0 Then
Exit Sub 'we don't want to run this if something already exists
End If
Call incrNumber(Me, strMsg, "ItemNoBox")
If strMsg <> vbNullString Then
MsgBox strMsg, vbInformation
End If
End Sub
Could you post incrNumber() routine code?

Regards.
Fish
Feb 22 '08 #2
Hi Fish,

Thanks for your reply. [ProjLink] is simply an element/variable of the [Equipment List] table. There are only two tables involved, [Equipment List] and [Project Info]. The tables are actually not linked to each other until the [Equipment Form Query], where element [ProjLink] from [Equipment List] table is linked (1:1) to element [ProjKey] from [Project Info] table. The relationship is 1:1 because there is always 1 record in the project table, and that one record applies to each record in the equipment list table. I'm guessing in that case many [equipment]:1 [project] would also work, but 1:1 has always worked for me.

As for the incrNumber macro, even if I exclude the macro completely by deleting the event and then just type the number manually, I still have the problem. I am also positive that the problem originates from the form. If I enter data through the query, everything works fine.

Also, I have just figured out how to cease the bug from occuring! In the form, if I include a control box for [ProjLink] and make it locked, everything works perfectly and the [Project Info] table doesn't grow. I have no idea why this was the ticket, but apparently it was all that was needed. However, I still would like to know why this fixes the problem, because in the past, the form worked properly even without the control box I just added. It had only recently stopped adding records properly after I did some design changes to the form. In fact, the rest of my forms work properly without this control box (ones for instruments, specialty items, and other things). Also, it would be useful to know how to declare a table as static and to force it to never grow so that this problem doesn't arise in the future.

Thanks!
Feb 22 '08 #3
FishVal
2,653 Expert 2GB
Actually, to the best of my knowledge, there is only one reason for that - an editable control on your form linked to any field of [Project Info] table. When form is on new record and the control gets any data, new record will be added to [Project Info] table.

Best regards.
Fish
Feb 23 '08 #4
Actually, to the best of my knowledge, there is only one reason for that - an editable control on your form linked to any field of [Project Info] table. When form is on new record and the control gets any data, new record will be added to [Project Info] table.

Best regards.
Fish
Hmm, that could explain something, I did throw in a control box that wasn't locked (since a user requested that it be unlocked) in one of my modifications to the form. It's still there though with the new control box that is locked which fixed the issue. Also, data wasn't being modified, but it was being accessed with a macro. Still seems strange.
Feb 25 '08 #5

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

Similar topics

3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
1
by: phaddock4 | last post by:
Being fairly inexperienced at Access 2000, i've been reading many posts here for the last several days, and testing myself to find the best approach to do the following in A2K: SET UP: I have...
5
by: deejayquai | last post by:
Hi I have a list of students undetaking various sports activities. Currently the students are listed in tblGroupMembers and I manually go into a form/subform and allocate each activity for each...
10
by: Thelma Lubkin | last post by:
My form/subform combination that allows user to display 'ColorSet' records, move to other records via a selector, to add,delete, and edit them, and to manage the related 'Color' records from the...
0
by: David | last post by:
Hi, I've been using MS Access as a front end to our remote MySQL db for a long time. I've just added a facility for clients to select a record to copy along with all its sub-records. The...
3
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we...
4
by: LetMeDoIt | last post by:
Greetings, I'm using ASP to retrieve from MSSQL and I then populate a table. After several months of successfull retrieves, this same code now bombs out. It turns out that if I clear out from...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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.