473,480 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Pre-populating foreign key when creating a new record

2 New Member
Hello,

I'm trying to pre-populate a foreign key field [client_ID] when creating a record; whether creating a new record in the table itself or a form.

table 1 = Clients
table 2 = Invoices

table Clients has the [Client_ID] field and all client data. The Invoice table contains many invoice records for the respective client record.

I've created a one to many relationship between the two tables, based on [client_ID]. So there is a foreign key field called [client_ID] in the Invoice table.

My problem is, when creating a new record in the Invoice table or a form using the Invoice table data, I cannot seem to find a way to pre-populate the foreign key field.
How would I do this? I have tried adding another field from the Client table, to the Invoice table called [Client_Nickname]. I can select a value in the dropdown field under the Invoice table, for [Client_Nickname] but it does not prepopulate the field in the Invoice table with the [Client_ID] value.

My goal is to have a Invoice form where I can create a new Invoice record, select the Client's name from a dropdown (or nickname) and have that client's ID field on the same form, pre-populate. As it is now, I have to select the [Client_Nickname] from a dropdown field then also select a value for the [Client_ID] dropdown field. Then save the record.
I'd rather just select client nickname and the client ID prepopulate if that makes any sense...

thank you.
Sep 29 '14 #1
3 3025
zmbd
5,501 Recognized Expert Moderator Expert
One way, and the way I tend to this,
Parent form to the parent table or query.
Child form to the details.

This way when you make your entry into the subform, the value fot the related field is entered into the child's record.
Sep 29 '14 #2
GKJR
108 New Member
There is an easy way to do this on a data entry form that doesn't require a subform at all.

1. Create a combo box or list box (both are essentially the same thing) that is bound to the Client_ID in the Invoice table (Foreign Key).
2. Define the Row Source property to contain the Client_ID and the Client_Name (2 columns) with an SQL statement.
3. Set the Bound Column on the Data tab to 1.
4. Set the Number of Columns on the Format tab to 2.
5. The Column Width property should look something like: 0"; 2" (I usually hide the ID field by setting the width to 0).

This is a critical method for making forms. One of the parts that threw me off when I was learning how to do this was really understanding the difference between the Control Source and the Row Source of your combo or list box. The Control Source determines what field in the underlying record source will take the value that it returns. The Row Source determines what options are available for the user to choose from based on an SQL statement.
Sep 30 '14 #3
accessdude
2 New Member
Thank you both, this is great information and the creating of the combo box and defining the row source property to contain both the Client_ID and the Client_Name solved my problem.
The new form works like a charm and allows me to create new records without entering a foreign key separately.
Oct 1 '14 #4

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

Similar topics

0
1059
by: Mary Lei | last post by:
After instaling db2 8.2.2 on a solaris box I ran a script that drops a database and then creates it. This scripts runs fine under db2 8.2.1 on linux. With 8.2.2 I got a mysterious error about...
0
2230
by: Claudiu | last post by:
Hi, I am storing word documents in embedded OLE fields (Access 2000). The ole field is bound to a "bound object frame". Whenever I create a new record the user must select "insert object"...
2
4700
by: CroDude | last post by:
Heya all! I have a weird problem when creating a texture brush in a Paint event. When program gets to the line where I'm creating a new TextureBrush object, it crashes with OutOfMemory...
2
1310
by: Patrick Spence | last post by:
(sorry 'bout the multipost) VS.NET 2003 v 7.1.3088 ..NET Framework v1.1.4322 XP Pro IIS 5.0 When I try to create a ASP.NET application, I get the following error... The Web server...
1
1789
by: Eric Voigt | last post by:
are there special settings applied to IIS5, when creating a webService in VS.NET? I wonder - because when I create a webService (let's call it webservice1) using VStudio.NET on my remote W2K...
1
1546
by: ReidarT | last post by:
The former post was wrong, the lines where concatenated so here it goes again. I am wrriting to a file (XML-format) and using FileOpen(1, "C:\vb\WebBrowser\WebBrowserControl\TESTFILE.XML",...
4
1926
by: Don | last post by:
When creating a new region for a control via a GraphicsPath object, it appears the entire rightmost column of pixels and bottom most row of pixels are not included in the region. I will try to...
9
5975
by: Joe Penora | last post by:
Hi All, How to add the HTML script when creating new ASPX page. After it is done I may need to add some Meta tags etc... but the html script is not there. Is there an option in the ASP.NET...
0
1002
by: Jerry Spence1 | last post by:
Can anyone point me in the right direction on how to set a license key when creating a licensed control dynamically? I have a licensed ActiveX component. Works fine when I put an instance on the...
5
5215
by: chip0105 | last post by:
When a form is opened fields are locked. When a new record is added (by pressing an add new record button), fields are unlocked. When the record is saved the fields are then locked again. ...
0
7044
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,...
1
6739
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
6929
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
5337
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,...
0
4481
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...
0
2995
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...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
bsmnconsultancy
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...

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.