Hi,
Be careful with a delete and a where clause based on <>. Make a backup
first.
Your problem seems to be that you supply a string, not a field name, so you
must use delimiter:
CurrentDb.Execute ("DELETE FROM tblOne WHERE tblTwo.[Id] <> " & cboId & "
AND tblname.[name] <> '" & Replace(cboName, "'", "''") & "' "),
dbFailOnError
where I added ' as delimiter, and duplicate any occurrence of it in cboName
content, if any, to be in accordance with what the database expect. If ID
is not numerical, also use delimiter:
CurrentDb.Execute ("DELETE FROM tblOne WHERE tblTwo.[Id] <> '" & cboId & "'
AND tblname.[name] <> '" & Replace(cboName, "'", "''") & "' "),
dbFailOnError
where, this time, I just add the ' delimiters.
You can use DoCmd.RunSQL to avoid the delimiter problem:
DoCmd.RunSQL "DELETE FROM tblOne WHERE tblTwo.[Id] <>
FROMS!FormNameHere!cboId
AND tblname.[name] <> FORMS!FormName!cboName"
You don't need delimiter because you refer to the container of the data, not
to the data, as constant. You don't put delimiter around the field name, as
example, only around constant. With your CurrentDb.Execute, you build a
string that will see the data as constant (the string send to
CurrentDb.Execute will be just that, a string, with the data from cbold and
cboName embedded into it as a constant), so, these constants need the
required delimiters ( quotes or # for dates). The DoCmd syntax uses the
container, so no delimiters required. CurrentDb does not understand the
FORMS!formName!ControlName syntax, but DoCmd does.
Hoping it may help
Vanderghast, Access MVP
Jochem Davids said:
Okok, I already answered my own question, by running two different SQL
queries.
The first one INSERTs all data from the first table to the second. The
second query deletes all data but NOT the data from my selected
ComboBoxes.
Nice work around he??
But now only just one minor thing doesn't work:
CurrentDb.Execute ("DELETE FROM tblOne WHERE tblTwo.[Id] <> " & cboId & "
AND tblname.[name] <> " & cboName & " "), dbFailOnError
This AND statement will not work?! I also tried && ... What should I use?
Is
it at all possible?
Jochem Davids said:
Hi Chris,
Thanks for your reply.
Access denies an INNER JOIN on my UPDATE sql statement... Is it at all
posible??
Jochem