Assigning a value On?

A

a24t42

I have a form in which I need to assign a specific value to a control
if you input data. I can write a macro to assign the value to the
control. What I am having problem with is what event do I assign it
to?

On the off chance that you open the form but decide not to create a
new record, I do not want to assign the value. If you input data, I
need to assign the value.

Hope that makes sense. Any help will be appreciated.
 
M

Mr B

I would normally use the "After Update" event of the control that I want the
user to enter data.
 
T

tina

try the following code in the form's BeforeUpdate event procedure, as

If Me.NewRecord Then Me!ControlName = <some value>

the check for "NewRecord" is necessary, unless you want the value in an
existing record to be overwritten. however, if you may have existing records
with no value in the control, and want a value added when the record is
edited, try the following code in the form's BeforeUpdate event procedure,
instead, as

If IsNull(Me!ControlName) Then Me!ControlName = <some value>

if the value needs to be assigned in all instances, whether or not a value
already exists, then just use

Me!ControlName = <some value>

again, in the form's BeforeUpdate event. in all code examples above, the
code goes all on one line, regardless of possible line-wrap in this post.

hth
 
Top