Hi,
I have a query to fill a recordset in my code. This query requires parameter values that I take from a form. I managed to make it work in Access 2007 using the following code.
Everything works perfectly in Access 2007, but when I wanted to run it in Access 2003 I realize the query was not giving me the right records. I realized it was because it wasn't taking the date parameters like Forms![fbr_Generer_Rapport]![txtDateDebut] properly. I don't have problems with other parameters, but this one that involeves a date.
Besides, I was thinking it could be a format date problem or something like that. Somebody have an idea why it is not working in Access 2003?
This is my query :
I have a query to fill a recordset in my code. This query requires parameter values that I take from a form. I managed to make it work in Access 2007 using the following code.
Code:
Set qdfQuery = currDb.QueryDefs("rql_Filtre_Rapport_General")
'Parametres pour la requête
qdfQuery![Forms!fbr_Generer_Rapport!txtDateDebut] = Forms![fbr_Generer_Rapport]![txtDateDebut]
qdfQuery![Forms!fbr_Generer_Rapport!txtDateFin] = Forms![fbr_Generer_Rapport]![txtDateFin]
qdfQuery![Forms!fbr_Generer_Rapport!txtNoEnregistrement] = Forms![fbr_Generer_Rapport]![txtNoEnregistrement]
qdfQuery![Forms!fbr_Generer_Rapport!cboContrat] = Forms![fbr_Generer_Rapport]![cboContrat]
qdfQuery![Forms!fbr_Generer_Rapport!cboRapport] = Forms![fbr_Generer_Rapport]![cboRapport]
qdfQuery![Forms!fbr_Generer_Rapport!cboLocalisation] = Forms![fbr_Generer_Rapport]![cboLocalisation]
qdfQuery![Forms!fbr_Generer_Rapport!cboActivite] = Forms![fbr_Generer_Rapport]![cboActivite]
qdfQuery![Forms!fbr_Generer_Rapport!cboLevee] = Forms![fbr_Generer_Rapport]![cboLevee]
qdfQuery![Forms!fbr_Generer_Rapport!cboDossier] = Forms![fbr_Generer_Rapport]![cboDossier]
qdfQuery![Forms!fbr_Generer_Rapport!cboQrt] = Forms![fbr_Generer_Rapport]![cboQrt]
qdfQuery![Forms!fbr_Generer_Rapport!cboDit] = Forms![fbr_Generer_Rapport]![cboDit]
qdfQuery![Forms!fbr_Generer_Rapport!cboDmt] = Forms![fbr_Generer_Rapport]![cboDmt]
qdfQuery![Forms!fbr_Generer_Rapport!cboMemo] = Forms![fbr_Generer_Rapport]![cboMemo]
qdfQuery![Forms!fbr_Generer_Rapport!cboAvenant] = Forms![fbr_Generer_Rapport]![cboAvenant]
Set rst = qdfQuery.OpenRecordset()
Everything works perfectly in Access 2007, but when I wanted to run it in Access 2003 I realize the query was not giving me the right records. I realized it was because it wasn't taking the date parameters like Forms![fbr_Generer_Rapport]![txtDateDebut] properly. I don't have problems with other parameters, but this one that involeves a date.
Besides, I was thinking it could be a format date problem or something like that. Somebody have an idea why it is not working in Access 2003?
This is my query :
Code:
SELECT t1.*, CStr([t1.NoFormulaire]) AS strNoFormulaire, t3.NumeroFormulaire AS NumeroUnique
FROM ((tbl_Rapport_Journalier AS t1 LEFT JOIN tbl_Rapport AS t2 ON t1.NoRapport = t2.NoRapport) LEFT JOIN tbl_Numero_Unique AS t3 ON t1.NoFormulaire = t3.NoFormulaire) LEFT JOIN tbl_Beton AS t4 ON t1.NoFormulaire = t4.noFormulaire
WHERE (
(DateValue(t1.DateRapport) >= IIF ([Forms]![fbr_Generer_Rapport]![txtDateDebut] = "" OR IsNull([Forms]![fbr_Generer_Rapport]![txtDateDebut]), #1900-01-01#, [Forms]![fbr_Generer_Rapport]![txtDateDebut]))
AND
(DateValue(t1.DateRapport) <= IIF ([Forms]![fbr_Generer_Rapport]![txtDateFin] = "" OR IsNull([Forms]![fbr_Generer_Rapport]![txtDateFin]), #2099-12-31#, [Forms]![fbr_Generer_Rapport]![txtDateFin]))
AND
(t3.NumeroFormulaire=[Forms]![fbr_Generer_Rapport]![txtNoEnregistrement] OR [Forms]![fbr_Generer_Rapport]![txtNoEnregistrement] Is Null)
AND
(t2.NoContrat=[Forms]![fbr_Generer_Rapport]![cboContrat] OR [Forms]![fbr_Generer_Rapport]![cboContrat] Is Null)
AND
(t1.NoRapport=[Forms]![fbr_Generer_Rapport]![cboRapport] OR [Forms]![fbr_Generer_Rapport]![cboRapport] Is Null)
AND
(t1.NoLocalisation=[Forms]![fbr_Generer_Rapport]![cboLocalisation] OR [Forms]![fbr_Generer_Rapport]![cboLocalisation] Is Null)
AND
(t1.NoActivite=[Forms]![fbr_Generer_Rapport]![cboActivite] OR [Forms]![fbr_Generer_Rapport]![cboActivite] Is Null)
AND
(t4.NoLevee=[Forms]![fbr_Generer_Rapport]![cboLevee] OR [Forms]![fbr_Generer_Rapport]![cboLevee] Is Null)
AND
(t1.NoDossier=[Forms]![fbr_Generer_Rapport]![cboDossier] OR [Forms]![fbr_Generer_Rapport]![cboDossier] Is Null)
AND
(t1.NoQrt=[Forms]![fbr_Generer_Rapport]![cboQrt] OR [Forms]![fbr_Generer_Rapport]![cboQrt] Is Null)
AND
(t1.NoDit=[Forms]![fbr_Generer_Rapport]![cboDit] OR [Forms]![fbr_Generer_Rapport]![cboDit] Is Null)
AND
(t1.NoDmt=[Forms]![fbr_Generer_Rapport]![cboDmt] OR [Forms]![fbr_Generer_Rapport]![cboDmt] Is Null)
AND
(t1.NoMemo=[Forms]![fbr_Generer_Rapport]![cboMemo] OR [Forms]![fbr_Generer_Rapport]![cboMemo] Is Null)
AND
(t1.NoAvenant=[Forms]![fbr_Generer_Rapport]![cboAvenant] OR [Forms]![fbr_Generer_Rapport]![cboAvenant] Is Null)
);