Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Requête en VB

2 réponses
Avatar
P-P
Bonjour,

J'essaie d'exécuter des requêtes en VB, cependant je dois mettre une
condition sur la requête en utilisant une variable que j'ai créé dans le
code, est-ce que cela est possible?

Voici mon code, la partie qui ne marche est celle où j'essaie d'exécuter la
requête (vers la fin).

Merci!!!

Private Sub cmdRunProjection_Click()
On Error GoTo Err_testpp_Click

Set dbRun = CodeDb()
Set db = CodeDb()
' étapes
' aller chercher la valeur de SimulationsHistoID
Set tblSimulationsHisto = dbRun.OpenRecordset("tblSimulationsHisto",
DB_OPEN_TABLE)
While Not tblSimulationsHisto.EOF
If tblSimulationsHisto!yesProjectionResults = -1 Then
SimulationsHistoID = tblSimulationsHisto!intSimulationsHistoID
' créer un enregistrement dans tblProjections
Set tblProjections = db.OpenRecordset("tblProjections",
DB_OPEN_TABLE)
tblProjections.AddNew
tblProjections!intSimulationsHistoID = SimulationsHistoID
tblProjections.Update
tblProjections.MoveLast
ProjectionsID = tblProjections!intProjectionsID
tblProjections.Close

' mettre à jour la date et l'heure de la projection
strSQL = "UPDATE tblProjections SET
tblProjections.dtmProjectionsDate = #" & Date & "# WHERE
(((tblProjections.intProjectionsID)=" & ProjectionsID & "));"
DoCmd.RunSQL strSQL
strSQL = "UPDATE tblProjections SET
tblProjections.dtmProjectionsTime = #" & Time() & "# WHERE
(((tblProjections.intProjectionsID)=" & ProjectionsID & "));"
DoCmd.RunSQL strSQL

' faire les calculs de projection et mettre les résultats dans
tblresultsProjections
' requête match date avec WHERE pour SimulationsHistoID
' ProjectionsID doit être égal à la valeur de la variable
définie plus haut

strSQL = "SELECT tblAssumptions.intGroupsID,
tblSimulationsHisto.intSimulationsHistoID,
tblResultsDataBenefits.intBenefitsID, tblResultsDataBenefits.intDataID,
tblSimulationsHisto.dtmProjectionDate, tblSimulationsHisto.dtmProjectionTime,
tblSimulations.strSimulationsDesc, Val([intdataid]) AS intDataFilter1,
Val(Year([dtmvaldate])) AS intAnnéeÉval,
Val(Right([tblAssumptions!strAssumptionsDesc],2)) AS intCatHypo,
tblBenefits.strName, tblBenefits.strBenefitType,
tblResultsDataBenefits.strValStatus, tblResultsDataBenefits.strValStatus,
tblResultsDataBenefits.curEBO, tblResultsDataBenefits.curABO,
tblResultsDataBenefits.curEBP, tblResultsDataBenefits.curNC,
tblResultsDataBenefits.dblEARSLElig, tblResultsDataBenefits.dblEARSLRet" & _
"FROM (tblSimulations INNER JOIN tblAssumptions ON
tblSimulations.intAssumptionsID = tblAssumptions.intAssumptionsID) INNER JOIN
(tblSimulationsHisto INNER JOIN (tblResultsDataBenefits INNER JOIN
tblBenefits ON tblResultsDataBenefits.intBenefitsID =
tblBenefits.intBenefitsID) ON tblSimulationsHisto.intSimulationsHistoID =
tblResultsDataBenefits.intSimulationsHistoID) ON
tblSimulations.intSimulationsID = tblSimulationsHisto.intSimulationsID WHERE
(((tblSimulationsHisto.dtmProjectionDate)=SimulationsHistoID));"
DoCmd.RunSQL strSQL

End If
tblSimulationsHisto.MoveNext
Wend
tblSimulationsHisto.Close

2 réponses

Avatar
Fabien
Bonjour,

J'essaie d'exécuter des requêtes en VB, cependant je dois mettre une
condition sur la requête en utilisant une variable que j'ai créé dans le
code, est-ce que cela est possible?

Voici mon code, la partie qui ne marche est celle où j'essaie d'exécuter la
requête (vers la fin).

Merci!!!

Private Sub cmdRunProjection_Click()
On Error GoTo Err_testpp_Click

Set dbRun = CodeDb()
Set db = CodeDb()
' étapes
' aller chercher la valeur de SimulationsHistoID
Set tblSimulationsHisto = dbRun.OpenRecordset("tblSimulationsHisto",
DB_OPEN_TABLE)
While Not tblSimulationsHisto.EOF
If tblSimulationsHisto!yesProjectionResults = -1 Then
SimulationsHistoID = tblSimulationsHisto!intSimulationsHistoID
' créer un enregistrement dans tblProjections
Set tblProjections = db.OpenRecordset("tblProjections",
DB_OPEN_TABLE)
tblProjections.AddNew
tblProjections!intSimulationsHistoID = SimulationsHistoID
tblProjections.Update
tblProjections.MoveLast
ProjectionsID = tblProjections!intProjectionsID
tblProjections.Close

' mettre à jour la date et l'heure de la projection
strSQL = "UPDATE tblProjections SET
tblProjections.dtmProjectionsDate = #" & Date & "# WHERE
(((tblProjections.intProjectionsID)=" & ProjectionsID & "));"
DoCmd.RunSQL strSQL
strSQL = "UPDATE tblProjections SET
tblProjections.dtmProjectionsTime = #" & Time() & "# WHERE
(((tblProjections.intProjectionsID)=" & ProjectionsID & "));"
DoCmd.RunSQL strSQL

' faire les calculs de projection et mettre les résultats dans
tblresultsProjections
' requête match date avec WHERE pour SimulationsHistoID
' ProjectionsID doit être égal à la valeur de la variable
définie plus haut

strSQL = "SELECT tblAssumptions.intGroupsID,
tblSimulationsHisto.intSimulationsHistoID,
tblResultsDataBenefits.intBenefitsID, tblResultsDataBenefits.intDataID,
tblSimulationsHisto.dtmProjectionDate, tblSimulationsHisto.dtmProjectionTime,
tblSimulations.strSimulationsDesc, Val([intdataid]) AS intDataFilter1,
Val(Year([dtmvaldate])) AS intAnnéeÉval,
Val(Right([tblAssumptions!strAssumptionsDesc],2)) AS intCatHypo,
tblBenefits.strName, tblBenefits.strBenefitType,
tblResultsDataBenefits.strValStatus, tblResultsDataBenefits.strValStatus,
tblResultsDataBenefits.curEBO, tblResultsDataBenefits.curABO,
tblResultsDataBenefits.curEBP, tblResultsDataBenefits.curNC,
tblResultsDataBenefits.dblEARSLElig, tblResultsDataBenefits.dblEARSLRet" & _
"FROM (tblSimulations INNER JOIN tblAssumptions ON
tblSimulations.intAssumptionsID = tblAssumptions.intAssumptionsID) INNER JOIN
(tblSimulationsHisto INNER JOIN (tblResultsDataBenefits INNER JOIN
tblBenefits ON tblResultsDataBenefits.intBenefitsID =
tblBenefits.intBenefitsID) ON tblSimulationsHisto.intSimulationsHistoID =
tblResultsDataBenefits.intSimulationsHistoID) ON
tblSimulations.intSimulationsID = tblSimulationsHisto.intSimulationsID WHERE
(((tblSimulationsHisto.dtmProjectionDate)=SimulationsHistoID));"
DoCmd.RunSQL strSQL

End If
tblSimulationsHisto.MoveNext
Wend
tblSimulationsHisto.Close
Bonjour

Si la variable est simulationshistoId
2 cas
elle est alpha :
[...]
WHERE (((tblSimulationsHisto.dtmProjectionDate)='" & SimulationsHistoID
"'));"
[...]
Elle est numérique :
[...]
WHERE (((tblSimulationsHisto.dtmProjectionDate)=" & SimulationsHistoID &
"));"
[...]
Si j'ai bien compris le problême ;-)

Avatar
P-P
Merci!!


Bonjour,

J'essaie d'exécuter des requêtes en VB, cependant je dois mettre une
condition sur la requête en utilisant une variable que j'ai créé dans le
code, est-ce que cela est possible?

Voici mon code, la partie qui ne marche est celle où j'essaie d'exécuter la
requête (vers la fin).

Merci!!!

Private Sub cmdRunProjection_Click()
On Error GoTo Err_testpp_Click

Set dbRun = CodeDb()
Set db = CodeDb()
' étapes
' aller chercher la valeur de SimulationsHistoID
Set tblSimulationsHisto = dbRun.OpenRecordset("tblSimulationsHisto",
DB_OPEN_TABLE)
While Not tblSimulationsHisto.EOF
If tblSimulationsHisto!yesProjectionResults = -1 Then
SimulationsHistoID = tblSimulationsHisto!intSimulationsHistoID
' créer un enregistrement dans tblProjections
Set tblProjections = db.OpenRecordset("tblProjections",
DB_OPEN_TABLE)
tblProjections.AddNew
tblProjections!intSimulationsHistoID = SimulationsHistoID
tblProjections.Update
tblProjections.MoveLast
ProjectionsID = tblProjections!intProjectionsID
tblProjections.Close

' mettre à jour la date et l'heure de la projection
strSQL = "UPDATE tblProjections SET
tblProjections.dtmProjectionsDate = #" & Date & "# WHERE
(((tblProjections.intProjectionsID)=" & ProjectionsID & "));"
DoCmd.RunSQL strSQL
strSQL = "UPDATE tblProjections SET
tblProjections.dtmProjectionsTime = #" & Time() & "# WHERE
(((tblProjections.intProjectionsID)=" & ProjectionsID & "));"
DoCmd.RunSQL strSQL

' faire les calculs de projection et mettre les résultats dans
tblresultsProjections
' requête match date avec WHERE pour SimulationsHistoID
' ProjectionsID doit être égal à la valeur de la variable
définie plus haut

strSQL = "SELECT tblAssumptions.intGroupsID,
tblSimulationsHisto.intSimulationsHistoID,
tblResultsDataBenefits.intBenefitsID, tblResultsDataBenefits.intDataID,
tblSimulationsHisto.dtmProjectionDate, tblSimulationsHisto.dtmProjectionTime,
tblSimulations.strSimulationsDesc, Val([intdataid]) AS intDataFilter1,
Val(Year([dtmvaldate])) AS intAnnéeÉval,
Val(Right([tblAssumptions!strAssumptionsDesc],2)) AS intCatHypo,
tblBenefits.strName, tblBenefits.strBenefitType,
tblResultsDataBenefits.strValStatus, tblResultsDataBenefits.strValStatus,
tblResultsDataBenefits.curEBO, tblResultsDataBenefits.curABO,
tblResultsDataBenefits.curEBP, tblResultsDataBenefits.curNC,
tblResultsDataBenefits.dblEARSLElig, tblResultsDataBenefits.dblEARSLRet" & _
"FROM (tblSimulations INNER JOIN tblAssumptions ON
tblSimulations.intAssumptionsID = tblAssumptions.intAssumptionsID) INNER JOIN
(tblSimulationsHisto INNER JOIN (tblResultsDataBenefits INNER JOIN
tblBenefits ON tblResultsDataBenefits.intBenefitsID =
tblBenefits.intBenefitsID) ON tblSimulationsHisto.intSimulationsHistoID =
tblResultsDataBenefits.intSimulationsHistoID) ON
tblSimulations.intSimulationsID = tblSimulationsHisto.intSimulationsID WHERE
(((tblSimulationsHisto.dtmProjectionDate)=SimulationsHistoID));"
DoCmd.RunSQL strSQL

End If
tblSimulationsHisto.MoveNext
Wend
tblSimulationsHisto.Close
Bonjour

Si la variable est simulationshistoId
2 cas
elle est alpha :
[...]
WHERE (((tblSimulationsHisto.dtmProjectionDate)='" & SimulationsHistoID
"'));"
[...]
Elle est numérique :
[...]
WHERE (((tblSimulationsHisto.dtmProjectionDate)=" & SimulationsHistoID &
"));"
[...]
Si j'ai bien compris le problême ;-)