Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access default value on form and subform

Posted on 2015-01-23
4
Medium Priority
?
752 Views
Last Modified: 2015-01-23
I want to set the default value of 2 fields in a parent form and 2 fields in a subform when a new record is added.

We have 1 table (Table A) containing 1 record having 4 fields that is used to retain the values that I want in the forms.

We have a parent form (Form 1) that contains a subform (Form 2).  Table A is not a data source for either form.  Other tables are required as the data sources.   There are at least 15 form controls on each form.

When a new record is entered into Form 1, we want 2 fields from Table A to be the default value in 2 form controls.  Same when a new record is entered into Form2, we want 2 fields from Table A to be the default value in 2 form controls.

Tried setting the default value of each form controls to the corresponding value in the Table A field but get a #Name error.

Any experts out there that can suggest how I might approach solving this?  Thanks!
0
Comment
Question by:clock1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Simon
ID: 40567324
something like this pseudocode?

on form_current()
if me.newrecord then
set rsdefaults=currentdb.openrecordset("TableA")
me.control1.value = rsdefaults("ctrl1").value
me.control2.value = rsdefaults("ctrl2").value
set rsdefaults =nothing
end if
end sub

But I'd ask the question why you don't just set the default values in the tabledefs? Is it because you need dynamic defaults?
0
 

Author Comment

by:clock1
ID: 40567340
SimonAdept

Believe I can get this to work.
Would this code go into the form_current for each form?
0
 
LVL 18

Accepted Solution

by:
Simon earned 2000 total points
ID: 40567347
Yes, it could go into form and subform (so that each new subform line gets the defaults).

The gotcha with it might be that you are 'dirtying' the form, so if user changes their mind about completing a record, they'll need to hit escape to clear the defaults to exit gracefully (or you have to do a me.undo in code if the user chooses not to save the latest record).
0
 

Author Closing Comment

by:clock1
ID: 40567351
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question