G
Guest
Hi everyone,
I need to use a recordset based on a union query that includes 3 parameters.
The calling instructions are:
Dim Base01 As DAO.Database
Dim ReqPCTUnion As Recordset
Const NmReqPCTUnion = "R_PCTUnion"
Set Base01 = CurrentDb
'Here I manually set the 3 parameters (this will be included in a loop later
on)
'CtrlPropF, CtrlCompteF and CtrlTitreF are 3 controls on the calling opened
form
'and are used in the query as parameters.
rep = FnCritèreNoProp("FermerTrans", 1)
CtrlPropF = rep
rep = FnCritèreNoCompte("FermerTrans", 1)
CtrlCompteF = rep
rep = FnCritèreNoTitre("FermerTrans", 11)
CtrlTitreF = rep
' DoCmd.OpenQuery "R_PCTUnion" 'Works fine and opens the querie correctly
Set ReqPCTUnion = Base01.OpenRecordset(NmReqPCTUnion) 'Produces an error
message
My problem occurs with the Set ReqPCTUnion =
Base01.OpenRecordset(NmReqPCTUnion)
I'm getting an error message from Access saying something like:
"Not enough parameters, 3 expected" (my translation, since I'm using a
french version of Access)
In my debug process, I tried to open the query with the DoCmd.OpenQuery
instruction and everything works fine and opens the query with the proper
values as parameters, no error. So I believe my SQL is OK.
I reproduce here the query SQL, in case someone finds something wrong. The
3 parameters are in the HAVING clause and the WHERE clause.
'R_PCTUnion
SELECT T_ÉtatTitre.NoTransaction, T_ÉtatTitre.NoPropriétaire,
T_ÉtatTitre.NoCompte, T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans,
T_ÉtatTitre.NoTypeTrans, T_ÉtatTitre.EnMain,T_ÉtatTitre.Statut
FROM T_ÉtatTitre
GROUP BY T_ÉtatTitre.NoTransaction, T_ÉtatTitre.NoPropriétaire,
T_ÉtatTitre.NoCompte, T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans,
T_ÉtatTitre.NoTypeTrans, T_ÉtatTitre.EnMain,T_ÉtatTitre.Statut
HAVING (((T_ÉtatTitre.NoPropriétaire)=[forms]![F_MenuPrincipal]![CtrlPropF])
AND ((T_ÉtatTitre.NoCompte)=[forms]![F_MenuPrincipal]![CtrlCompteF]) AND
((T_ÉtatTitre.NoTitre)=[forms]![F_MenuPrincipal]![CtrlTitreF]) AND
((T_ÉtatTitre.NoTypeTrans)<>0) AND ((T_ÉtatTitre.EnMain)=0))
ORDER BY T_ÉtatTitre.NoPropriétaire, T_ÉtatTitre.NoCompte,
T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans;
UNION SELECT T_ÉtatTitre.NoTransaction, T_ÉtatTitre.NoPropriétaire,
T_ÉtatTitre.NoCompte, T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans,
T_ÉtatTitre.NoTypeTrans, T_ÉtatTitre.EnMain,T_ÉtatTitre.Statut
FROM T_ÉtatTitre
WHERE (((T_ÉtatTitre.NoPropriétaire)=[forms]![F_MenuPrincipal]![CtrlPropF])
AND ((T_ÉtatTitre.NoCompte)=[forms]![F_MenuPrincipal]![CtrlCompteF]) AND
((T_ÉtatTitre.NoTitre)=[forms]![F_MenuPrincipal]![CtrlTitreF]) AND
((T_ÉtatTitre.NoTypeTrans)=0) AND ((T_ÉtatTitre.EnMain)=0))
ORDER BY T_ÉtatTitre.NoPropriétaire, T_ÉtatTitre.NoCompte,
T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans;
Since the Docmd.OpenQuery works, I could use that method to feed another
query that would fill a temporary table that I could then use as recordset,
but this seems to be a long, not very efficient way of doing things. I would
prefer to use a recordset based directly on the union query especially since
this portion of code will be included in a loop and be executed a certain
number of passes (~75-100).
I have searched few specific newsgroups without success.
Any suggestion on how to set a recordset based on a union query including
parameters ?
Any help would be greatly appreciated.
Michel
I need to use a recordset based on a union query that includes 3 parameters.
The calling instructions are:
Dim Base01 As DAO.Database
Dim ReqPCTUnion As Recordset
Const NmReqPCTUnion = "R_PCTUnion"
Set Base01 = CurrentDb
'Here I manually set the 3 parameters (this will be included in a loop later
on)
'CtrlPropF, CtrlCompteF and CtrlTitreF are 3 controls on the calling opened
form
'and are used in the query as parameters.
rep = FnCritèreNoProp("FermerTrans", 1)
CtrlPropF = rep
rep = FnCritèreNoCompte("FermerTrans", 1)
CtrlCompteF = rep
rep = FnCritèreNoTitre("FermerTrans", 11)
CtrlTitreF = rep
' DoCmd.OpenQuery "R_PCTUnion" 'Works fine and opens the querie correctly
Set ReqPCTUnion = Base01.OpenRecordset(NmReqPCTUnion) 'Produces an error
message
My problem occurs with the Set ReqPCTUnion =
Base01.OpenRecordset(NmReqPCTUnion)
I'm getting an error message from Access saying something like:
"Not enough parameters, 3 expected" (my translation, since I'm using a
french version of Access)
In my debug process, I tried to open the query with the DoCmd.OpenQuery
instruction and everything works fine and opens the query with the proper
values as parameters, no error. So I believe my SQL is OK.
I reproduce here the query SQL, in case someone finds something wrong. The
3 parameters are in the HAVING clause and the WHERE clause.
'R_PCTUnion
SELECT T_ÉtatTitre.NoTransaction, T_ÉtatTitre.NoPropriétaire,
T_ÉtatTitre.NoCompte, T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans,
T_ÉtatTitre.NoTypeTrans, T_ÉtatTitre.EnMain,T_ÉtatTitre.Statut
FROM T_ÉtatTitre
GROUP BY T_ÉtatTitre.NoTransaction, T_ÉtatTitre.NoPropriétaire,
T_ÉtatTitre.NoCompte, T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans,
T_ÉtatTitre.NoTypeTrans, T_ÉtatTitre.EnMain,T_ÉtatTitre.Statut
HAVING (((T_ÉtatTitre.NoPropriétaire)=[forms]![F_MenuPrincipal]![CtrlPropF])
AND ((T_ÉtatTitre.NoCompte)=[forms]![F_MenuPrincipal]![CtrlCompteF]) AND
((T_ÉtatTitre.NoTitre)=[forms]![F_MenuPrincipal]![CtrlTitreF]) AND
((T_ÉtatTitre.NoTypeTrans)<>0) AND ((T_ÉtatTitre.EnMain)=0))
ORDER BY T_ÉtatTitre.NoPropriétaire, T_ÉtatTitre.NoCompte,
T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans;
UNION SELECT T_ÉtatTitre.NoTransaction, T_ÉtatTitre.NoPropriétaire,
T_ÉtatTitre.NoCompte, T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans,
T_ÉtatTitre.NoTypeTrans, T_ÉtatTitre.EnMain,T_ÉtatTitre.Statut
FROM T_ÉtatTitre
WHERE (((T_ÉtatTitre.NoPropriétaire)=[forms]![F_MenuPrincipal]![CtrlPropF])
AND ((T_ÉtatTitre.NoCompte)=[forms]![F_MenuPrincipal]![CtrlCompteF]) AND
((T_ÉtatTitre.NoTitre)=[forms]![F_MenuPrincipal]![CtrlTitreF]) AND
((T_ÉtatTitre.NoTypeTrans)=0) AND ((T_ÉtatTitre.EnMain)=0))
ORDER BY T_ÉtatTitre.NoPropriétaire, T_ÉtatTitre.NoCompte,
T_ÉtatTitre.NoTitre, T_ÉtatTitre.DateTrans;
Since the Docmd.OpenQuery works, I could use that method to feed another
query that would fill a temporary table that I could then use as recordset,
but this seems to be a long, not very efficient way of doing things. I would
prefer to use a recordset based directly on the union query especially since
this portion of code will be included in a loop and be executed a certain
number of passes (~75-100).
I have searched few specific newsgroups without success.
Any suggestion on how to set a recordset based on a union query including
parameters ?
Any help would be greatly appreciated.
Michel