Update query question

S

Silvio

Hello, I would like to update a record by looking at the value from a form
combo box column(1). I have tried Forms![Lab Works Manager]![cmbTo].column(1)
but it does not work. The bond column(0) has the ID, but in this case I need
to use the actual value from column(1) and not column(0). Any idea how?

Thank you,
Silvio
 
J

John Spencer

Add a hidden control to your form and set its value to
=Forms![Lab Works Manager]![cmbTo].column(1)
Then you can reference that hidden control in the query.

Your other option is to write a VBA function and pass in the name of the form,
the name of the control and the column number. Something like the following
UNTESTED idea.

Public Function fGetColumnValue(strFormName as string _
, StrControlName as String _
, intColumn as Long)

fGetColumnValue= Forms(strFormName).Controls(strControlName).Column(intColumn)

End Function


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
J

John W. Vinson

Hello, I would like to update a record by looking at the value from a form
combo box column(1). I have tried Forms![Lab Works Manager]![cmbTo].column(1)
but it does not work. The bond column(0) has the ID, but in this case I need
to use the actual value from column(1) and not column(0). Any idea how?

Thank you,
Silvio

What are the RowSource, ColumnCount and BoundColumn properties of the combo?
Confusingly, the Bound Column property is 1-based while the Column() property
is zero based - it seems you're aware of that but it's a possible source of
confusion.
 
S

Silvio

Thanks John, your suggestion works great (hiden control).


John Spencer said:
Add a hidden control to your form and set its value to
=Forms![Lab Works Manager]![cmbTo].column(1)
Then you can reference that hidden control in the query.

Your other option is to write a VBA function and pass in the name of the form,
the name of the control and the column number. Something like the following
UNTESTED idea.

Public Function fGetColumnValue(strFormName as string _
, StrControlName as String _
, intColumn as Long)

fGetColumnValue= Forms(strFormName).Controls(strControlName).Column(intColumn)

End Function


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
Hello, I would like to update a record by looking at the value from a form
combo box column(1). I have tried Forms![Lab Works Manager]![cmbTo].column(1)
but it does not work. The bond column(0) has the ID, but in this case I need
to use the actual value from column(1) and not column(0). Any idea how?

Thank you,
Silvio
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top