I only see one parameter there (Forms].[RTEsbyRTE].[RTE]): you've got the
value for Division hard-coded to 1.
That means your code should be:
Dim qdfAction As DAO.QueryDef
Set qdfAction = CurrentDb.QueryDefs("qryAppendRTEHistory")
qdfAction.Parameters("[Forms].[RTEsbyRTE].[RTE]").value =
[Forms].[RTEsbyRTE].[RTE].value
qdfAction.Execute dbFailOnError
Sorry, I missed the fact that you were redundantly looping through the
Parameters collection already, and should have pointed that out earlier.
You
could try:
Dim qdfAction As DAO.QueryDef
Dim prmCurr As DAO.Parameter
Set qdfAction = CurrentDb.QueryDefs("qryAppendRTEHistory")
For Each prmCurr In qdfAction.Parameters
prmCurr.value = Eval(prmCurr.Name)
Next prmCurr
qdfAction.Execute dbFailOnError
but technically your SQL should have a PARAMETERS clause at the
beginning:
PARAMETERS [Forms].[RTEsbyRTE].[RTE] TEXT;
INSERT INTO RTEHistoryTable ( RTE, ActualUPTTurnoverDate,
ScheduledRECSTurnoverDate, ActualRECSTurnoverDate, UPTSCR, RECSSCR,
CurrentBaselineVerision, ScheduledUPTTurnoverDate, CommitmentDate,
Comments,
Division )
SELECT RTEInventoryRTEQuery.RTE,
RTEInventoryRTEQuery.ActualUPTTurnoverDate,
RTEInventoryRTEQuery.ScheduledRECSTurnoverDate,
RTEInventoryRTEQuery.ActualRECSTurnoverDate, RTEInventoryRTEQuery.UPTSCR,
RTEInventoryRTEQuery.RECSSCR,
RTEInventoryRTEQuery.CurrentBaselineVersionLabel,
RTEInventoryRTEQuery.ScheduledUPTTurnoverDate,
RTEInventoryRTEQuery.CommitmentDate, RTEInventoryRTEQuery.Comments,
RTEInventoryRTEQuery.Division
FROM RTEInventoryRTEQuery
WHERE (((RTEInventoryRTEQuery.RTE)=[Forms].[RTEsbyRTE].[RTE]) AND
((RTEInventoryRTEQuery.Division)=1));
Note that if RTE is a numeric field, you'd replace TEXT with a different
type, such as LONG.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
OEB said:
Yes. Here is the query:
INSERT INTO RTEHistoryTable ( RTE, ActualUPTTurnoverDate,
ScheduledRECSTurnoverDate, ActualRECSTurnoverDate, UPTSCR, RECSSCR,
CurrentBaselineVerision, ScheduledUPTTurnoverDate, CommitmentDate,
Comments,
Division )
SELECT RTEInventoryRTEQuery.RTE,
RTEInventoryRTEQuery.ActualUPTTurnoverDate,
RTEInventoryRTEQuery.ScheduledRECSTurnoverDate,
RTEInventoryRTEQuery.ActualRECSTurnoverDate,
RTEInventoryRTEQuery.UPTSCR,
RTEInventoryRTEQuery.RECSSCR,
RTEInventoryRTEQuery.CurrentBaselineVersionLabel,
RTEInventoryRTEQuery.ScheduledUPTTurnoverDate,
RTEInventoryRTEQuery.CommitmentDate, RTEInventoryRTEQuery.Comments,
RTEInventoryRTEQuery.Division
FROM RTEInventoryRTEQuery
WHERE (((RTEInventoryRTEQuery.RTE)=[Forms].[RTEsbyRTE].[RTE]) AND
((RTEInventoryRTEQuery.Division)=1));
But when I add the code I get an error saying object does not support
this
property or method. And then the first qdfAction says the item is not
found.
:
Does the query refer to [Forms].[RTEsbyRTE].[RTE] and
[Forms].[RTEsbyRTE].[Division]? If so, that's how you need to refer to
the
parameters:
qdfAction.Parameters("[Forms].[RTEsbyRTE].[RTE]").value =
[Forms].[RTEsbyRTE].[RTE].value
qdfAction.Parameters("[Forms].[RTEsbyRTE].[Division]").value =
[Forms].[RTEsbyRTE].[Division].value
If that doesn't solve the problem, take a look at the SQL of your
query.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
I am getting object not found in collection with this code.
Dim qdfAction As DAO.QueryDef
Dim prmCurr As DAO.Parameter
Set qdfAction = CurrentDb.QueryDefs("qryAppendRTEHistory")
qdfAction.Parameters("RTE").value = [Forms].[RTEsbyRTE].[RTE].value
qdfAction.Parameters("Division").value =
[Forms].[RTEsbyRTE].[Division].value
Set qdfAction = CurrentDb.QueryDefs("qryAppendRTEHistory")
For Each prmCurr In qdfAction.Parameters
prmCurr.value = Eval(prmCurr.Name)
Next prmCurr
qdfAction.Execute dbFailOnError
What am I doing wrong?
:
Can I pass parameters when doing an DoCmd.OpenQuery? What is the
syntax?
Since the query is used for different forms, I can't put the
parameters
in
the query.