Solved

Access default value on form and subform

Posted on 2015-01-23
4
558 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
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:SimonAdept
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:
SimonAdept earned 500 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Correct ordering 16 48
Multiple queries for a form 14 22
ms/access user defined type not defined 4 10
Help with SQl and UNION 3 16
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now