Setting values

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

Guest

Here is the code

Private Sub Form_Close()
MsgBox (Me.Subform1_Sel.Value)
MsgBox (Me.Subform1_Sel_Field.Value)
Me.Subform1_Sel_Field.Value = "IPA"
End Sub

On my form I have a field called Subform1_Sel_Field. Its control source is
Subform1_Sel. The form's record source is called Proj_Cat (a table)

Three questions, of which the last is most important:
1. 1st msgbox when executes shows a value (let's say CPI), where exactly is
this value coming from, the table or the form?

2. same question

3. 3rd line give me a run-time error 2448, cannot assign a value to this
object. This is driving me crazy since the msgbox actually displays the
current value (let's say CPI) and I just want to change the value in the
table before closing the form.

Thanks..
 
Hi,
All data displayed on bound forms is taken from the table or query that is
the form's recordsource.
Your controls are simply displaying the data that is in your table, so the
value you get from a control is really what's in your table.
Make sense?
It's sometimes important to distinguish between controls on your form and fields in your
table. I personally never name a control with the same name as the field it's bound to.
You can't have a 'field' on a form, only controls that can be bound to fields.

As to your 3rd question, you can't change a value in the form's close event, it's too late
at that point.
 
Thanks for the reply Dan. I moved the code to the on current event and it
worked fine.

Couple of followups:

1. I made a test and seems I can also use the unload event. However, when I
go into design the form when it is open, it gives me the error below. Any
idea why? (minor inconvience, so don't spend alot of time on this one)

2. I noticed Me.xxx alot in the posts. What is this, where is the doc on
it (some post mention MS Access help, but can't find it. Where do I find
this and other system type variables/fields?

3. I am having problems explaining to another MVP programtically
implementing a filter by form in different post. If you could throw your two
cents worth in I would appreciate it.

Again, thanks for the support you MVP's give us!!!
 
Dan,

I have the same problem, but I can not get my brain to get in gear to figure
it out. I have a regisitration fee that is computed on the form and I want
to save it for later reporting.

Private Sub Form_Close()

Me.Reg_Fee = Me.Registrant_Subtotal

End Sub

But I get an error 'can't assign a value to this object'. I am stuck, I
know it is something that I have done before, but I am lost.

tia,
michael
 
Good afternoon.
I'd been struggling with that same infuriatingly vague error and just
cracked it. I don't know if this will help you or not, but just in case:

I had a form Addresses used as a subform on several other forms. There
is an AddressLabel control which functions either as a bound control to
Description, where there are multiple Addresses or is just a flat text field
for forms that only have one Address.
Hope that made some sense. What was happening was this: opening
Addresses on one form, my code set the ControlSource to Description. Opening
it in another form, the code (tried to) set the control's value to "Street"
as a default Address Description. What I had to do to fix it was to insert a
line to set the control's ControlSource to "" before I could set its value.

This is the actual code:

Private Sub Form_Current()
If Recordset.Fields.Count > 10 Then ' Yes, it's a hack
AddressLabel.ControlSource = "Description"
Else
AddressLabel.ControlSource = "" ' Needed to add this line
AddressLabel.Value = "Street" ' Had been throwing Error 2448: "You
can't assign a value to this object"
End If
End Sub
 
Back
Top