B
Bob Quintal
the values are all read-only. You can however run a SQLI am working on a database that deals with oil companies and
their wells
Occasionally, an oil company might sell some or all of their
wells to another company so I need an easy way to select a
group of wells and change the associated company. I created a
simple form with the following controls;
1st combo box (cboCurrentOperator) that selects
OperatorID(primary key) and CompanyName from tblOperators
2nd combo box (cboNewOperator) that selects the same as the
1st
a list box (lstWells) that selects WellID(primary key)
OperatorID and WellName from tblWells filtered by the 1st
combo box. Multi Select property is set to extended.
an Update button (cmdUpdate) with the following code for the
on click event
Dim ctl As Control
Dim varItem As Variant
Set ctl = Me.lstWells
For Each varItem In ctl.ItemsSelected
ctl.Column(1) = Me.cboNewOperator
Next varItem
This does not work (I also tried adding .Column(0) to the end
of Me.cboNewOperator) so apparently I can't use the Column
reference for this type of code. I think maybe some type of
UPDATE sql statement might be what i need but I don't know how
to get it to update only the items that were selected in the
list box.
Am I on the right track, or going about this all wrong?
Any help would be very much appreciated.
You can't change a value using the listbox column() propert.
statement that UPDATEs one record inside your varItem
I hope that a column of that listbox contains the primary key to
the wells table. You will need that for the whereClause.
PK = 0 '<- set this to the correct column.
For Each varItem In ctl.ItemsSelected
strSQL = "UPDATE wells SET operator " _
& "VALUES (""" Me.cboNewOperator & """) " _
& "WHERE wellid = " & me.ctl.Column(PK) & ";"
Docmd.RunSQL strSQL
Next varItem
..
I'll let you prettify this, and test for bugs. I don't have your
db at hand to test with.