473,396 Members | 1,968 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.

Foreign Key Won't Enter In Subform

My problem is in a form/subform. On the main form I have an unbound listbox
named OptionsInPlan. In the OnCurrent event of the main form I set the value of
the listbox with the code:
Me!OptionsInPlan.Value = Me!OptionsInPlan.ItemData(0)
For some records there are no rows in the listbox.

I want to have the subform track the value of the listbox so I set the
LinkMaster property to OptionsInPlan and the LinkChild property to ElevationID.
When I make selections in the listbox or navigate with the navigation buttons
the subform tracks the value of the listbox and displays the correct
corresponding records.

My problem lies when I try to add a new record to the subform. I have unbound
textboxes directly above each field in the subform and in the last textbox I use
the AfterUpdate event to execute the Add New method to add the values in the 5
textboxes to the underlying table. When the AfterUpdate event fires, the new
record appears in the subform for a moment and then disappears. When I check the
table, the 5 field values have been added but the foreign key(ElevationID) has
not. I have tried it with and without this code in the Add New method:
Rst!ElevationID = Me.Parent!OptionsInPlan and get the same results.

Can someone help with a solution to this problem?

Thanks!

Traci
Nov 13 '05 #1
1 2477
Hi Traci

The fact that the record appears briefly and then disappears suggest that
Access is creating the record, but does not think that it matches the
LinkMasterFields/LinkChildFields.

Use the Immediate Window to ask Access what is going on.
While the form is running, and after the new record disappears, press
Ctrl+G. Enter some expressions like:
? Forms!MyForm!MySubformControl.LinkMasterFields
? Forms!MyForm!MySubformControl.LinkChildFields

Also ask it whether the data type is being interpreted correcty, e.g.:
? TypeName(Forms!MyForm!OptionsInPlan)
?
TypeName(Forms!MyForm!MySubformControl.Form![WhateverTheMatchingFieldIsInThe
Subform])

For example, if the bound column of the list box is a Number field, you may
be able to solve the problem by setting the Format property of the list box
to General Number (since that indicates the data type for the unbound
listbox).

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Traci" <tm******@earthlink.net> wrote in message
news:zT******************@newsread3.news.atl.earth link.net...
My problem is in a form/subform. On the main form I have an unbound listbox named OptionsInPlan. In the OnCurrent event of the main form I set the value of the listbox with the code:
Me!OptionsInPlan.Value = Me!OptionsInPlan.ItemData(0)
For some records there are no rows in the listbox.

I want to have the subform track the value of the listbox so I set the
LinkMaster property to OptionsInPlan and the LinkChild property to ElevationID. When I make selections in the listbox or navigate with the navigation buttons the subform tracks the value of the listbox and displays the correct
corresponding records.

My problem lies when I try to add a new record to the subform. I have unbound textboxes directly above each field in the subform and in the last textbox I use the AfterUpdate event to execute the Add New method to add the values in the 5 textboxes to the underlying table. When the AfterUpdate event fires, the new record appears in the subform for a moment and then disappears. When I check the table, the 5 field values have been added but the foreign key(ElevationID) has not. I have tried it with and without this code in the Add New method:
Rst!ElevationID = Me.Parent!OptionsInPlan and get the same results.

Can someone help with a solution to this problem?

Thanks!

Traci

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ed Havelaar | last post by:
Hi, Hope someone can help. Here's the scenario: I have two MSAccess tables MainTab and SubTab. MainTab has an autonumber 'id' column as primary key. Subtab has this id column as a foreign...
3
by: DFS | last post by:
I've been working around this for years (I believe), so I figured someone here might know: Why won't a crosstab query accept a value from a form reference? TRANSFORM...
5
by: misscrf | last post by:
I have a database in 3rd normal form ( or pretty darn close) I have all of my reports working well, but the main report is having issues. This is for candidates applying for jobs. This report...
9
by: martin | last post by:
please help I have a table with member details and another one to many table used for payments. The problem is that the foreign key is not saved into the payment table causing the table to not...
1
by: MJ | last post by:
I have a form that won't allow me to enter data. The sub-forms work fine, but the main one won't allow input or a new record. What am I overlooking?
3
by: Alex Satrapa | last post by:
There's some mention in the (old!) documentation that constraints such as foreign keys won't include data from inheriting tables, eg: CREATE TABLE foo ( id SERIAL PRIMARY KEY ); CREATE TABLE...
1
by: abefuzzleduser2 | last post by:
we use Access 2000 with linked tables in SQL Server 2000. I have a form and a datasheet subform based on a table. This was not related to the parent table before and I was changing nvarchars to...
1
by: jpatchak | last post by:
Hello, I have a form with a subform. The mainform has a primary key () and the subform has a foreign key (). When new records are added in the mainform, I get an error message that says, "ODBC...
3
by: Darin | last post by:
I have a problem I just can't figure out. I have a form with a subform, and the recordsource of the subform has criteria based on some unbound fields in the parent form so that data in the parent...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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:
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.