0

I'm entering data by using a query on a subform. I want to auto populate a job number to each new line I add to that subform.

tbl_Jobs
[Job_ID] <Primary Key
JID1001
JID1002
JID1003

tbl_Job_Tasks
[ID Auto][Job_ID][Task]
1        JID1002  TASK1
2        JID1002  TASK2
3        JID1002  TASK3
4        JID1001  TASK1

Here's my query at the most basic level...

SELECT tbl_Job_Tasks.[Job_ID], tbl_Job_Tasks.[Category], tbl_Job_Tasks.[Task]
FROM tbl_Job_Tasks
WHERE (([Job_ID]="JID1002"));

What I want to be able to do is hide the Job_ID column and have it auto populate for the user if they decide to enter a new task for their Job. Currently if I enter a new task I have to specify the Job_ID to use. This query is being used on a sub form that pulls its Job_ID from the parent form, so in a perfect world the end user would not have to re-enter the Job_ID.

Is this possible?

Thank you,

2
  • Is Job_ID being used as your parent/child relationship to the parent form. Just use tbl_Job_Tasks as the source for your sub, and let Access take care of it. Commented Mar 24, 2017 at 12:52
  • Job_ID is the relation holder, but my real query is doing a bunch of sorting of the tasks before it displays them. Just using this as an example since it's a little simpler. Commented Mar 24, 2017 at 12:57

2 Answers 2

1

If the subform is linked to the parent form correctly (Using the Link Master/Child Fields property) the child records foreign key (in your case tbl_Job_Tasks.Job_ID) should be filled out automatically.

You shouldn't even need the query unless you are filtering the sub forms records in some odd way.

Edit - Have a look here http://www.access-diva.com/f2.html for a solution to your unbound problem.

Sign up to request clarification or add additional context in comments.

6 Comments

Yes I'm doing custom sorting. For the sake of easy understanding I pulled out all the sorting I'm doing to sort the tasks into different categories and orders.
That shouldn't matter - you would still use the Master / Child relationship to control the sub form. As long as the query is updateable. If it isn't you may need to rationalise the query and do the sorting filtering on the subform not the query.
If I try to set master or child on my sub form I get a "Can't build a link between unbound forms" error, I assumed that was because I'm using a query as my source object, is that correct?
I'm pulling sorting information from an additional table (tbl_Task_Category: [Task Category], [Order]) which is why using a query is important.
You can set a link on any field / text box - just type the control name in, ignore the builder. You can use this technique to bind two subforms together on a unbound main form. See the link in my edit.
|
0

Just to sum up the solution.

  • Link the Master and Child Fields to the sub form.
  • If you're getting a "Can't build a link between unbound forms" error, you can go into design view and manually type in the Parent/Child fields.

After that, the field will update automatically when entering a new row.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.