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

Subforms: adding new records: setting one specific field

Thanks in advance for everyone's help. Here's my issue:

I have subforms throughout my main form. Everything works fine and dandy. When I add a new record to the subform results, I would like to automatically set a field. For instance: My subform lists functions that belong to a department. I would like to be able to add functions directly in the subform and automatically set the "department ID" field, to match a dropdown that is on the main form... I'd love to do this without even pulling in the "Department ID" field into the subform results...

Any idea how to do this (without having a button on the main form to create the new record in the table with the specified field, then refreshing the subform query)?

Right now I'm working around it by having the field within the subform, manually selecting the Department ID to ensure it's correctly linked.
Aug 5 '09 #1
5 3505
yarbrough40
320 100+
ok so are you saying that you are making a dropdown box selection in the main form and wanting that selection to populate into a control in a subform when you add a record to that subform rather than updating a query and refreshing? - you want to update the form control directly... is this right?
Aug 6 '09 #2
missinglinq
3,532 Expert 2GB
Since this is a one-to-many relationship, department - t o - functions, you should be doing this as a standard main form to subform. The main form should hold information about each department, including its ID, and the subform the same ID number as well as its functions. To enter a new record in the subform, you first move to the record for the department in the main form, then add your record in the subform. If the form-subform is linked correctly, the ID will automatically be entered in the subform (functions) record.

Welcome to Bytes!

Linq ;0)>
.
Aug 6 '09 #3
Thanks yarbrough. You're basically correct. on the main form, I use the dropdown (combobox) to select the department I'm currently working on.

That updates the query for my subform, pulling all functions that match the deptartment ID. Within the subform query, I'm pulling in departmentID so when I add a new record, I can select it from the dropdown. My goal is to skip this last step so that when I add a new record, my code will automatically updates the DepartmentID for that record within the subform to match the current department (selected from the main form's dropdown)..

Sorry if that's confusing.. thanks everyone!


@yarbrough40
Aug 6 '09 #4
yarbrough40
320 100+
Looks to me that this is all you're trying to do:
Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_Change()
  2. Me.TextBox2.Value = Forms!Mainform1!ComboBox1.Value
  3. End Sub
  4.  
  5. Private Sub TextBox2_AfterUpdate()
  6. DoCmd.RunCommand acCmdSaveRecord
  7. End Sub
Aug 6 '09 #5
Yeah I don't think my question came across just right.. I found a workaround, last night.. My main form: a combobox that has a list of departments. My subform: a subform query that pulls a list of functions that have a DepartmentID that matches the current selection of the combobox on my mainform. When someone adds a new record to the subform query results, 'on exit'ing that subform I query that table for any records with a blank DepartmentID, then set it to match the current selection of the combobox (on my main form)..

This seems to work especially since someone can input multiple records before exiting the subform table/query..

Thanks anyway for the assistance. Let me know if there's a more direct way.. Thank you.

@yarbrough40
Aug 6 '09 #6

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

Similar topics

0
by: Jenni | last post by:
I currently have a query that is joining two distinct pools of information and turning them into one records with a unique identifier This query is dependent on criteria passed from a form in a...
6
by: Steve | last post by:
I have a form, primary subform and secondary subform. A tab control takes up all the area of the primary subform. There are about 15 tabs on the tabcontrol. Each tab contains fields from the same...
0
by: Jack | last post by:
Gday everyone, I'm dearly hoping Stephen Lebans is going to update his masterpeice to stop the mouse wheel scrolling to work on subforms *he has indicated this to me but of course beggers can't...
12
by: Paul T. RONG | last post by:
Is it possible to divide a tall subform with 80 records to two subforms each with 40 records? Dear All, What I have: Tables: tblProduct, tblOrder, tblOrderDetail
0
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main...
2
by: Terry | last post by:
Hello, I wonder if anyone can shed light on this problem for me. I have an Access 97 front end with an SQL 2000 database. There is a Business main form with an Owner subform and corresponding...
3
by: tlyczko | last post by:
I have a main form with 2 subforms, each subform references different data in the same table. How do I make sure each subform only creates NEW records in the referenced table and do not...
7
by: philelpko | last post by:
Good Morning all, I have a main form with 3 subforms. All of the input data on all the forms is stored in the same table. I started getting the message "the changes you requested to the table...
4
by: paquer | last post by:
Hello' How do I get the subform to print along with the main form? I want my user's to be able to go in the field with a printout of the info they need to populate in the database. So when they...
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
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
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
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.