R
Rob Parker
I am attempting to run an update query (a saved query in my database)
from code, and keep getting an error message (3061, Too few
parameters, expected 2).
The SQL of the query is:
UPDATE DAT_Arisings_Remarks SET DAT_Arisings_Remarks.ImageFile =
ChangeFileLink([ImageFile],[Forms]![frmSetupDatabase]![txtOldFolder],
[Forms]![frmSetupDatabase]![txtFolder])
WHERE (((Left([ImageFile],Len([Forms]![frmSetupDatabase]!
[txtOldFolder])))=[Forms]![frmSetupDatabase]![txtOldFolder]))
WITH OWNERACCESS OPTION;
It is designed to change portion of a path/filename from the string in
txtOldfolder to the string in txtFolder; it gets these values from
textbox controls on frmSetupDatabase. It runs perfectly well from the
database window, but fails when I try to run it from code.
My initial code was:
CurrentDb.Execute "qryChangeLinks_DAT_Arisings_Remarks",
dbFailOnError
I've tried adding a parameter statement to the saved query:
PARAMETERS [Forms]![frmSetupDatabase]![txtOldFolder] Text ( 255 ),
[Forms]![frmSetupDatabase]![txtFolder] Text ( 255 );
Again, the query runs fine from the database window, but gives error
3061 when run from code.
I've replaced the saved query name in the code with a string
containing the SQL of the query (both with and without the Parameters
clause), in this fashion:
strSQL = "UPDATE ... "
CurrentDb.Execute strSQL, dbFailOnError
and it still fails. The SQL string is correct; if I print it to the
immediate window, then cut/paste to a new query, it runs OK.
I've even tried replacing CurrentDb with:
Dim db As Database
Set db = DBEngine(0)(0)
db.Execute ...
[I don't think this should be necessary, but I'm trying everything I
can think of] Same error.
What is going on here? I'm at a complete loss.
TIA,
Rob
from code, and keep getting an error message (3061, Too few
parameters, expected 2).
The SQL of the query is:
UPDATE DAT_Arisings_Remarks SET DAT_Arisings_Remarks.ImageFile =
ChangeFileLink([ImageFile],[Forms]![frmSetupDatabase]![txtOldFolder],
[Forms]![frmSetupDatabase]![txtFolder])
WHERE (((Left([ImageFile],Len([Forms]![frmSetupDatabase]!
[txtOldFolder])))=[Forms]![frmSetupDatabase]![txtOldFolder]))
WITH OWNERACCESS OPTION;
It is designed to change portion of a path/filename from the string in
txtOldfolder to the string in txtFolder; it gets these values from
textbox controls on frmSetupDatabase. It runs perfectly well from the
database window, but fails when I try to run it from code.
My initial code was:
CurrentDb.Execute "qryChangeLinks_DAT_Arisings_Remarks",
dbFailOnError
I've tried adding a parameter statement to the saved query:
PARAMETERS [Forms]![frmSetupDatabase]![txtOldFolder] Text ( 255 ),
[Forms]![frmSetupDatabase]![txtFolder] Text ( 255 );
Again, the query runs fine from the database window, but gives error
3061 when run from code.
I've replaced the saved query name in the code with a string
containing the SQL of the query (both with and without the Parameters
clause), in this fashion:
strSQL = "UPDATE ... "
CurrentDb.Execute strSQL, dbFailOnError
and it still fails. The SQL string is correct; if I print it to the
immediate window, then cut/paste to a new query, it runs OK.
I've even tried replacing CurrentDb with:
Dim db As Database
Set db = DBEngine(0)(0)
db.Execute ...
[I don't think this should be necessary, but I'm trying everything I
can think of] Same error.
What is going on here? I'm at a complete loss.
TIA,
Rob