In news:(E-Mail Removed),
Rob Parker <(E-Mail Removed)> wrote:
> Some additional information:
>
> If I remove the WHERE clause from my query, I still get the error. So
> I presume that it's coming from the references to the two textbox
> controls in the ChangeFileLink function.
Right. You see, when you use CurrentDb.Execute to run an action query,
or CurrentDb.OpenRecordset to run a select query, you're asking DAO to
interpret and process the query all by itself, without any preliminary
handling by Access. But DAO doesn't know anything about forms and
controls. As far as DAO is concerned, those form & control references
are just parameters that need to be filled in with values before the
query can be executed.
When *Access* runs the query, it looks for parameters that it can
interpret as form & control references, and fills in the values
automatically before handing the query off to DAO to execute. Any
parameters it can't resolve that way, it prompts you for. But your code
is using DAO, and Access isn't involved, so you have to resolve the
parameters yourself, or else eliminate them.
If this were an inline SQL string, you could just embed the control
values directly in the string. But since this is a saved query, you can
use a trick involving the DAO QueryDef object to get them resolved.
Here's how:
'----- start of "air code" -----
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Set db = CurrentDb
Set qdf = db.QueryDefs("qryChangeLinks_DAT_Arisings_Remarks")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
qdf.Execute dbFailOnError
Set qdf = Nothing
Set db = Nothing
'----- end of "air code" -----
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)