Saving form field Value to Control

  • Thread starter Thread starter LJG
  • Start date Start date
L

LJG

I have a form field that gets a value from another form. I need to save the
form field value to a control and have tried using the following code with
no luck:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.txt3yrrate = Me.txt3_rate
End Sub

txt3yrrate is my control, txt3_rate is the form field.

TIA

Les
 
LJG said:
I have a form field that gets a value from another form. I need to
save the form field value to a control and have tried using the
following code with no luck:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.txt3yrrate = Me.txt3_rate
End Sub

txt3yrrate is my control, txt3_rate is the form field.

Just to clarify...txt3yrrate is a control that you populate with a value from
another form and txt3_rate is a control on your form that is bound to a field in
the form's RecordSource and your goal is for the value to be saved into that
field. If that is correct then your code looks ok. What happens (or doesn't)?
 
Hey Rick,

txt3_rate is the control which is populated with the data from another form.
txt3yrrate is bound to the forms record source.

Basically nothing happens, no value is captured or error given?

Thanks
Les
 
LJG said:
Hey Rick,

txt3_rate is the control which is populated with the data from
another form. txt3yrrate is bound to the forms record source.

Basically nothing happens, no value is captured or error given?

Put a break point on the line. That will cause the code to pause at that spot.
Then you can hover the mouse cursor over Me.txt3_rate and a popup will tell you
what value is in that control. My guess is that it will be null. Are you sure
you aren't confusing two controls with similar names or someting? If you *see*
a value in the control txt3_rate then I don't understand why what you're doing
wouldn't work.

txt3_rate isn't a ComboBox by any chance is it?
 
txt3_rate is a value FROM a combo box, I thought adding a field that gets
the value from a combo box, then add it to the control would be the best
way.

With the break point it shows a value of 0

Thanks
Les
 
LJG said:
txt3_rate is a value FROM a combo box, I thought adding a field that
gets the value from a combo box, then add it to the control would be
the best way.

With the break point it shows a value of 0

Many (most if made with the wizard) ComboBoxes contain one value while
displaying another. Undoubtedly this is what is happening to you. If the
displayed column is the second one (most commonly it would be) then you can
use...

txt3yrrate = txt3_rate.Column(1)

Column numbering begins with zero.

At this point I'm a bit puzzled why you are doing this though. If txt3_rate is
a ComboBox why not just bind it to the table field and eliminate the second
control entirely?
 
Tried Binding it the first time and had this same problem, hence I tried to
add this method to get the value then get the value from a form
field...thinking it would be easier.......several hours later and still
struggling.

The method you suggested also does not work as the field it is getting the
value from 'txt3_rate' has no columns, and gives me an error

This is the code I used to get the value into txt3_rate:

=frmLeaseRates.Form!cboRates.Column(1)

If I try it into the bound control 'txt3yrrate' and get an error message:

The value you entered is not valid for this field
 
LJG said:
Tried Binding it the first time and had this same problem, hence I
tried to add this method to get the value then get the value from a
form field...thinking it would be easier.......several hours later
and still struggling.

The method you suggested also does not work as the field it is
getting the value from 'txt3_rate' has no columns, and gives me an
error

You did say it was a ComboBox right? If so then it has columns (at least 1
anyway).
This is the code I used to get the value into txt3_rate:

=frmLeaseRates.Form!cboRates.Column(1)

That is not code. That is a ControlSource expression. Code would not have an
equals sign at the start of it.
If I try it into the bound control 'txt3yrrate' and get an error
message:
The value you entered is not valid for this field

It is sounding more and more like you have made some basic error in setting up
your table and form and have been trying additional incorrect processes in order
to work around the original error(s). Why don't you start from the beginning
and explain what it is you are trying to do? Using a ComboBox that is bound to
a field and gets its choices from another table is pretty standard fair. There
should be no need for an additional control or code.
 
Hi Rick,

Sorted it now thanks, simply added a control source to my form...all working
fine now....sometimes a bit of lateral thinking does help

Regards
Les
 
Back
Top