Solved

Access default value on form and subform

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

820 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