Default value ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
I have a table that has two fields that of type number
On the form level, I want to have value of the first field become the
default value of the second field.
I thought I might have some VBA code behind the afterupdate event of the
first field to have the default value of the second field set....
I don't know if I am heading the right way. Can I get some help?
 
You're on right steps. Use the first textbox's AfterUpdate event to write
the data into the second textbox (don't use DefaultValue of that second
textbox if you want the data to appear in the current record, as
DefaultValue property will cause data to appear only when a new record is
being created).

Private Sub TextBox1_AfterUpdate()
Me.TextBox2.Value = Me.TextBox1.Value
End Sub
 
Ken,
First thanks for the help.
Second, how do i avoid updating field two if field one is updated sometime
later when field two's value has been edited to a different value then what
the afterupdate event has set in the first place... I can see that, the value
in field two is updated as field one triggers the afterupdate event.

Thanks

--
niuginikiwi
Nelson, New Zealand


Ken Snell (MVP) said:
You're on right steps. Use the first textbox's AfterUpdate event to write
the data into the second textbox (don't use DefaultValue of that second
textbox if you want the data to appear in the current record, as
DefaultValue property will cause data to appear only when a new record is
being created).

Private Sub TextBox1_AfterUpdate()
Me.TextBox2.Value = Me.TextBox1.Value
End Sub
 
In the properties sheet set TextBox2 Enabled to False (No)

and:

Private sub TextBox1_AfterUpdate()

If isNull(me.TextBox2) Then
Me.TextBox2.Value = Me.TextBox1.Value
End If

End Sub

Regards/JK

niuginikiwi said:
Ken,
First thanks for the help.
Second, how do i avoid updating field two if field one is updated sometime
later when field two's value has been edited to a different value then
what
the afterupdate event has set in the first place... I can see that, the
value
in field two is updated as field one triggers the afterupdate event.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top