autofill field if blank

  • Thread starter Thread starter Lori
  • Start date Start date
L

Lori

I need help! I have a field called "Benchmark descp" in a
subform which is linked to a main form. I want the descp
field to automatically update/fill with the descp. of a
field called "Stdr Desc" from the main form IF 2 things
are true, otherwise leave untouched. 1. If field "Select
sample benchmark?] " is true AND field "Benchmark descp"
is null. Basiclly if the field already has a desp, I don't
want to overwrite it. The below code works only if a
record already exists. I tab off of the check field and
desp field will update if null or leave alone if something
already there. BUT.... if a new record is being created,
it does not work(cause as you tab from the ck field, it's
like the desp field noesn't exist yet to varify) so it
doesn't fill. The below code is want I have in the got
focus field "Benchmark descp".

Private Sub Benchmark_descp_GotFocus()
' Copy "Stdr Descp". as "Benchmark descp" after ck is
selected as true and if Benchmark descp is null

If Forms![mainform]![subform].Form![Select sample
benchmark?] = True And Forms![ mainform]![ subform].Form!
[Benchmark descp] = "" Then
Forms![ mainform]![ subform].Form![Benchmark descp] =
Forms![ mainform].Form![Stdr Desc]

End If
End Sub


Thanks (e-mail address removed)12.WI.US
 
Possibly, you need to save newly created record first
(even if it is blank) and then run your sub.
 
Lori said:
I need help! I have a field called "Benchmark descp" in a
subform which is linked to a main form. I want the descp
field to automatically update/fill with the descp. of a
field called "Stdr Desc" from the main form IF 2 things
are true, otherwise leave untouched. 1. If field "Select
sample benchmark?] " is true AND field "Benchmark descp"
is null. Basiclly if the field already has a desp, I don't
want to overwrite it. The below code works only if a
record already exists. I tab off of the check field and
desp field will update if null or leave alone if something
already there. BUT.... if a new record is being created,
it does not work(cause as you tab from the ck field, it's
like the desp field noesn't exist yet to varify) so it
doesn't fill. The below code is want I have in the got
focus field "Benchmark descp".

Private Sub Benchmark_descp_GotFocus()
' Copy "Stdr Descp". as "Benchmark descp" after ck is
selected as true and if Benchmark descp is null

If Forms![mainform]![subform].Form![Select sample
benchmark?] = True And Forms![ mainform]![ subform].Form!
[Benchmark descp] = "" Then
Forms![ mainform]![ subform].Form![Benchmark descp] =
Forms![ mainform].Form![Stdr Desc]


I think this may be caused by a confusion between a field
and a control. A field is a column in the form's record
source table/query, while a control is a thingy on the form
(e.g. a text box control displays the value of a field). I
make that distinction here because the problem might be
caused by using the name of a field when you should probably
use the name of the control bound to the field, they can
(and should) be different.

Another point is that you said you want to check if descp is
Null, but you're checking if it is a ZLS (zero length
string). These are two very different values.

Where is this code? If it's running in the subform's
module, you can simplify the code by using Me instead of the
full full form-subform references:

If Me![Select sample benchmark?] = True _
And Nz(Me![Benchmark descp], "") = "" Then
Me![Benchmark descp] = Parent![Stdr Desc]
End If
 
Back
Top