Solved

Access default value on form and subform

Posted on 2015-01-23
4
578 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: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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

863 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

26 Experts available now in Live!

Get 1:1 Help Now