can't assign a value to this object

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

Guest

I'm a VB/SQL guy looking at an access program for a client (I did not write
this program. The following code in a module fails with the error Can't
assign a value to this object:

Me!frmCtrOrders("OrderType") = "O"

The field OrderType on the form frmCtrOrders is a list box ("O" does seems
to be one of the allowable items in the list). This form is a subform of a
form called frmClientOrder. The list box does not appear to be bound to
anything.

From within the form itself I can see the field in the list of available
properties by typing me.ordertype. But in the debug window (when the code
fails) I cannot see this field in any of the property lists that I try to
generate.

It seems like the program may not be referencing the field in a way that
Access can understand. Any advice will be very much appreciated.

Kevin
 
Me!frmCtrOrders("OrderType") = "O"

The Me object usually refers to the form itself[1], which is unlikely to
have a member called frmCtrOrders. The correct answer is probably one of:-

Me!OrderType = "O"
Me("OrderType") = "O"
Me.Controls("OrderType") = "O" ' longhand version the previous ones

Forms!frmCtrOrders!OrderType = "O"
Forms("frmCtrOrders").Controls("OrderType") = "O"

etc Once you have the hang of Access objects, the rest is easy if you
already know VB.

[1] Specifically, it refers to the object that owns the running code; in
practice this means the form in a form module, or a user-written object in
a class module.

Hope it helps


Tim F
 
Hi Kevin,

Some things to check:

Is "OrderType" the name of a field in frmCtrOrders's recordsource as
well as of the listbox control?

Values of the listbox's RowSource, ControlSource, ColumnCount and
BoundColumn properties.

In the debug window, try referring to the listbox like this, where XXX
is the name of the subform control on the parent form (which often but
not always has the same name as the subform itself:

Forms("frmClientOrder").Controls("XXX").Form.Controls("OrderType")
 
Back
Top