Autopopulate gets Run Time Error 2448 (1 Viewer)

M Costumes

Member
Local time
Today, 03:41
Joined
Feb 9, 2021
Messages
75
I have a multi-value sub-form based on an Inventory table where the user selects an InvnetoryID from a cbo box and it autopopulates the appropriate fields (setID and RentalRate). It fills SetID just fine, but will not populate RentalRate with the value from the Inventory table. Inventory.RentalRate is set to currency. This is my VBA:
Code:
Private Sub cboInventoryID_AfterUpdate()
Me.txtSetID.Value = Me.cboInventoryID.Column(2)
Me.txtRentalRate.Value = Me.cboInventoryID.Column(3)
End Sub
When I test it, I get a run-time error 2448 "can't assign value to this object" When I run debug, it points to the last line. I've tried changing that line to
Code:
Me!txtRentalRate.Value = Val(Me!.cboInventoryID.Column(3))
and it did the same thing.

I'm very new to all of this, and have searched here and other forums/google in general and I've not quite found a solution. Any ideas?
 
NOTE: in vba,columns begin with zero.
So cbo.colums(3) means you have 4 columns. (In the property)
Did u set the combo to have 4 columns?
Or
Did u have 3 columns ,and mean to use cbo.colums(2)
 
Yes, there are 4 columns total:

0) record ID (autonumber)
1) InventoryID (text)
2) SetID (text)
3) RentalRate (currency)

the cbo box is bound to col 1
 
2448 "can't assign value to this object"
The error is what it says. There is a reason you cannot assign a value to txtRentalRate. The most common reason is that it is a calculated control.
 
The error is what it says. There is a reason you cannot assign a value to txtRentalRate. The most common reason is that it is a calculated control.
Not a calculation in this case.
 
What is the control source of txtRentalRate? What is the datatype of the control source?
 
What is the control source of txtRentalRate? What is the datatype of the control source?
control source: =[Inventory]![RentalRate]
data type is currency

I may very well have it pointed to the wrong thing. But the value from that filed is what I want it to display. I've tried changing the control source to
RentalRateText = Str([RentalRate])
and it will return the same error, but show $0 in the field instead of just leaving it blank.
 
Could this be based in how I've got the form and related tables set up?
 
As I said, that is a calculated field. And so is RentalRateText = Str([RentalRate]).
The control source should be a field name in the forms recordsource.
You Cannot assign a value to a calcualted control.
 
Also if you select an inventory ID then none of this should be assigned to a field in another table. You just need to join on the inventory id.

Could this be based in how I've got the form and related tables set up?
Exactly. Can you explain your tables? I am guessing this is not correctly (normalized) designed or you are storing info that you just need to link to.
 
Also if you select an inventory ID then none of this should be assigned to a field in another table. You just need to join on the inventory id.


Exactly. Can you explain your tables? I am guessing this is not correctly (normalized) designed or you are storing info that you just need to link to.
I started another thread, thinking my tables were the culprit. It explains my set-up better.
 
remove:

=[Inventory]![RentalRate]

from txtRentalRate. you will not be able to programmatically assign value to this textbox because
it is Bound to an Expression.

either make it Bound to a field (if you want to save it) or Unbound (no control source).
 
Looks like my issue was a combination of things: tables were not normalized, and my column counts were also incorrect. With those in mind, I scrapped the original form, started over, and got it working. Thanks all for your input!
 

Users who are viewing this thread

Back
Top Bottom