Returning or referencing the "Dirty" Value from a Textbox (?)

  • Thread starter Thread starter croy
  • Start date Start date
C

croy

How can the value typed into a textbox in a record not yet
saved, be extracted? In the Help, I've noticed "OldValue",
but nothing for Dirty, or New Value.
 
croy said:
How can the value typed into a textbox in a record not yet
saved, be extracted? In the Help, I've noticed "OldValue",
but nothing for Dirty, or New Value.

textbox.SetFocus
NewValue = textbox.Text

(textbox must have the focus in order to access its .Text property).

..Text contains newly typed and unsaved info
..Value contains saved info
 
If you have moved the focus off the control, and it is bound, then the
control should have both Value, and OldValue properties.

As Stewart says, if the control has the focus, then you can use the .text
propety to get the text in the control. However, referring to a controls
..text property when it does not have the focus will raise an error.

HTH
Dale
 
If you have moved the focus off the control, and it is bound, then the
control should have both Value, and OldValue properties.


It is a bound field.

Hmmm. In a new record, I overtype the Default Value for the
control "txtMyField", with the Value that I want, and tab to
the next field. The record is not saved yet. If I
understand you correctly, returning the Value for the
control "txtMyField" will produce the value that I typed.

Is that correct?

As Stewart says, if the control has the focus, then you can use the .text
propety to get the text in the control. However, referring to a controls
.text property when it does not have the focus will raise an error.


But if the control is bound, the .text property would be the
same as its .value property? Or the .text property no
longer exists after tabbing away from the field? Or none of
the above?
 
Croy,

If you are editing the value in a control, and that control has the focus,
then the Value property of the control will return what was in the control
before you started typing. Once you leave that control, the controls value
you typed into the control will be accessable through the Value property,
and the value that was there before you made any changes will be in the
OldValue property.

These values are not actually written to the record and the record saved
until you either move to another record, or save the record you are on
(setting the forms Dirty property to False forces Access to write that
record). If you cancel your changes (Hit the Escape key) or issue a me.Undo
command, Access will set the Value of the control equal to the OldValue of
that control.

If you return the focus to a control (txtMyField.SetFocus), then the .Text
property will contain the same value as the the .Value property.

Try this,

Create a new table and give it 2 text fields
Create a new form, bound to the table you just created.
Add two textboxes (txtMyField1, and txtMyField2) and bind the controls to
the fields in the forms recordsource.
Set the forms cycle property to "Current Record"
Add the following to the Forms code module:

Private Sub txtMyField1_GotFocus

msgbox "Value:" & me.txtMyField1.Value & vbcrlf _
& "Text:" & me.txtMyField1.Text & vbcrlf _
& "OldValue:" & me.txtMyField1.OldValue

End Sub

Private Sub txtMyField1_Change

msgbox "Value:" & me.txtMyField1.Value & vbcrlf _
& "Text:" & me.txtMyField1.Text & vbcrlf _
& "OldValue:" & me.txtMyField1.OldValue


End Sub

Private Sub txtMyField2_GotFocus

msgbox "Value:" & me.txtMyField1.Value & vbcrlf _
& "Text:" & me.txtMyField1.Text & vbcrlf _
& "OldValue:" & me.txtMyField1.OldValue

End Sub

Now, place your cursor int txtMyField1. You will get a messagebox
displaying all of the above values
Now, type a couple of characters. You will get a messagebox after each
character is pressed showing you the values in each of the fields
Now, tab into the next textbox, you will now see the values again, as they
exist after you have departed that control
Now tab again, should take you back to txtMyField1, on the same record, and
will display all three values again.

HTH
Dale
 
Croy,

If you are editing the value in a control, and that control has the focus,
then the Value property of the control will return what was in the control
before you started typing. Once you leave that control, the controls value
you typed into the control will be accessable through the Value property,
and the value that was there before you made any changes will be in the
OldValue property.

These values are not actually written to the record and the record saved
until you either move to another record, or save the record you are on
(setting the forms Dirty property to False forces Access to write that
record). If you cancel your changes (Hit the Escape key) or issue a me.Undo
command, Access will set the Value of the control equal to the OldValue of
that control.

If you return the focus to a control (txtMyField.SetFocus), then the .Text
property will contain the same value as the the .Value property.

Try this,

Create a new table and give it 2 text fields
Create a new form, bound to the table you just created.
Add two textboxes (txtMyField1, and txtMyField2) and bind the controls to
the fields in the forms recordsource.
Set the forms cycle property to "Current Record"
Add the following to the Forms code module:

Private Sub txtMyField1_GotFocus

msgbox "Value:" & me.txtMyField1.Value & vbcrlf _
& "Text:" & me.txtMyField1.Text & vbcrlf _
& "OldValue:" & me.txtMyField1.OldValue

End Sub

Private Sub txtMyField1_Change

msgbox "Value:" & me.txtMyField1.Value & vbcrlf _
& "Text:" & me.txtMyField1.Text & vbcrlf _
& "OldValue:" & me.txtMyField1.OldValue


End Sub

Private Sub txtMyField2_GotFocus

msgbox "Value:" & me.txtMyField1.Value & vbcrlf _
& "Text:" & me.txtMyField1.Text & vbcrlf _
& "OldValue:" & me.txtMyField1.OldValue

End Sub

Now, place your cursor int txtMyField1. You will get a messagebox
displaying all of the above values
Now, type a couple of characters. You will get a messagebox after each
character is pressed showing you the values in each of the fields
Now, tab into the next textbox, you will now see the values again, as they
exist after you have departed that control
Now tab again, should take you back to txtMyField1, on the same record, and
will display all three values again.

HTH
Dale


Thanks Dale, I think that nails it for me.

This has been a big help.
 
textbox.SetFocus
NewValue = textbox.Text

(textbox must have the focus in order to access its .Text property).

.Text contains newly typed and unsaved info
.Value contains saved info


Thanks Stuart. You and Dale have helped immensly.
 
Back
Top