Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defaulting fields for new records enterd in a subform.

Status
Not open for further replies.

dapotter

Programmer
Oct 9, 2004
32
US
I am creating a form to enter data into a table. I want to be able to enter several records where certain fields are identical without having to re-enter those fields every time. I've added unbound edit boxes for the user to enter the data that may not change for several records (e.g. Customer and Date). I use those fields to create a query to be used as the record source for a subform (for which the 'Link Child Fields' and Link Master Fields' properties are set to null). What I have so far displays existing data just fine. If I enter an existing customer/date combination, the subform populates with the correct data. What I want to be able to do now is use the subform to enter a new record.

As you probably predicted, the record created using the subform contains all the data entered in the subform, but the fields represented by the unbound edit boxes in the main form are unpopulated. How can I force the new records to contain the data used as criteria for the query defining the subform? I've tried adding code to the AfterInsert event of the subform, but that causes my code creating the subforms data source to not work.

Any help (including solutions completely different from what I'm attempting) would be greatly appreciated.

Don
 
You may play with the DefaultValue property of the Customer and Date controls in the subform.
You may also consider the BeforeInsert event procedure instead of the AfterInsert one.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

I do use the Customer and Date fields to limit the set of data that appears in the subform, but I don't include those fields in the subform (which I display in the datasheet view). I don't want the user to see those fields, since they appear to be included in the main form. I guess I could include them with the values defaulted as you suggest (based on the entries from the main form). The user would probably see the correct data already there and tab past them anyway. It's not my ideal solution, but if I can get it to work, I'll be satisfied.

Thanks for you help,
Don

By the way, I had actually started with the BeforeUpdate event procedure, but it yielded the same problem.
 
but it yielded the same problem
Which problem doing what ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I will have to refresh my memory on exactly what was happening. I abandoned my efforts to add code to the subform relatively early last night. I am currently at work, but the project I started this thread for is an at-home project. I'll try to find time tonight to remember what sort of errors I was receiving and follow up then.
 
PHV,

I'm not sure what the difference between last night and tonight is, but I was able to code the subform to get the behavior I need. Thanks so much for your time.

Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top