Link to home
Start Free TrialLog in
Avatar of clock1
clock1

asked on

Access default value on form and subform

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!
Avatar of Simon
Simon
Flag of United Kingdom of Great Britain and Northern Ireland image

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?
Avatar of clock1
clock1

ASKER

SimonAdept

Believe I can get this to work.
Would this code go into the form_current for each form?
ASKER CERTIFIED SOLUTION
Avatar of Simon
Simon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clock1

ASKER

Thanks