Delete Combined Value

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

Guest

I have a strange situation that I could use some help on. I have set up a combo box that has as its Row Source as a select query that combines the value of two fields. Thus you get as your options to select in the box "Location - Machine", where location and machine are two value that come from a record in the "Equipment" table. What I would like to do is set a button to delete whatever is selected in the combo box from the table, that is the specific record that is show as a combination of two fields. I can do this for a single field selected in a combo box, but not for this arrangement. If anybody knows of a way to set this up I would really appreciate some assistance

Thank you for your time on my situatio

Rich Adams
 
The easiest way would be if there is a unique id field for each of these
records, then include it in the combobox also, but in a hidden column
(width=0). You could then use the value of this unique id field to delete
the record. You would use the Column property of the combobox to refer to
this value. The Column property is zero based so, the first column is 0, the
second is 1, etc.

Example:
ValueToDelete=Me.cboMyCombo.Column(0)

If you don't have that available, you'll need to break apart the string in
the combobox into its 2 individual items, you can then determine which
record to delete.

Example:
strSQL="Delete * From Equipment Where Location='" & strLocation & "' And
Machine='" & strMachine & "'"
CurrentDb.Execute strSQL, dbFailOnError
Me.cboMyCombo.Requery

--
Wayne Morgan
Microsoft Access MVP


Rich Adams said:
I have a strange situation that I could use some help on. I have set up a
combo box that has as its Row Source as a select query that combines the
value of two fields. Thus you get as your options to select in the box
"Location - Machine", where location and machine are two value that come
from a record in the "Equipment" table. What I would like to do is set a
button to delete whatever is selected in the combo box from the table, that
is the specific record that is show as a combination of two fields. I can
do this for a single field selected in a combo box, but not for this
arrangement. If anybody knows of a way to set this up I would really
appreciate some assistance.
 
You need to concatenate the value into the SQL string. Since this is a
number, it will need no extra quotes around it.

strSQL = "Delete * From Equipment Where AutoNumber =" & ValueToDelete


--
Wayne Morgan
MS Access MVP


Rich Adams said:
Ok, I took your suggestion and am using the autonumber field value to do
the delete. I get the correct number assigned to ValueToDelete when I put
this into my code. But it has an error when it gets to the thrid line
below. The error says:
(To few Parameters, Expected 1.) - what do I need to do to fix this, I am
not sure what is wrong, but my guess would be it is the syntax in line 2.
 
Back
Top