GarnierFlorian
Messages postés129Date d'inscriptionmardi 27 mai 2008StatutMembreDernière intervention26 juillet 2011
-
12 nov. 2010 à 09:30
GarnierFlorian
Messages postés129Date d'inscriptionmardi 27 mai 2008StatutMembreDernière intervention26 juillet 2011
-
12 nov. 2010 à 11:44
Bonjour à tous !
Mon problème se situe, je pense, au niveau de mes paramètres que je passe pour exécuter ma requète. Ce que je souhaite faire, récupérer toutes les infos qui correspondent au mois et l'année récupérer dans ma form !
Je vous met directement tout mon code, depuis le début de mon module, ce n'est pas très long :
Sub Recuperation()
Dim ss_cmd As ADODB.Command
Dim ss_parmoi As ADODB.Parameter
Dim ss_parann As ADODB.Parameter
Dim ss_rst As ADODB.Recordset
On Error GoTo Recuperation_Error
'Fonction permettant de se connecter aux tables foxpro
Connexion
If FLGCNX = True Then
'On déclare la command
Set ss_cmd = New ADODB.Command
With ss_cmd
.ActiveConnection = CNXFOX
.CommandType = adCmdText
.NamedParameters = True
End With
Set ss_parmoi = New ADODB.Parameter
Set ss_parann = New ADODB.Parameter
With ss_parmoi
.Direction = adParamInputOutput
.Type = adInteger
.Name = "ChoixMois"
End With
With ss_parann
.Direction = adParamInputOutput
.Type = adInteger
.Name = "ChoixAnnee"
End With
'SelectionRequeteProspect
ss_cmd.Parameters.Append ss_parmoi
ss_cmd.Parameters.Append ss_parann
ss_parmoi.Value = CInt(RPT.MOI)
ss_parann.Value = CInt(RPT.ANN)
RESEXE.REQRPT = "SELECT DISTINCT pays.nompay,COUNT(client.numctr) AS nbprospect" & _
" FROM pays,client" & _
" WHERE client.codpay = pays.codpay" & _
" AND flgprp = 1" & _
" AND MONTH(client.datcre) = " & ss_parmoi & _
" AND YEAR(client.datcre) = " & ss_parann & _
" GROUP BY pays.nompay" & _
" ORDER BY pays.nompay"
ss_cmd.CommandText = "PARAMETERS ss_parmoi Integer ,ss_parann Integer;" & RESEXE.REQRPT
'On déclare le recordset
Set ss_rst = New ADODB.Recordset
'Exécute la requête
With ss_rst
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
End With
ss_rst.Open ss_cmd
'Fonctions/procédures diverses
ss_rst.Close
Set ss_cmd = Nothing
Set ss_rst = Nothing
End If
'Fonction permettant de se déconnecter aux tables foxpro
Deconnexion
On Error GoTo 0
Exit Sub
Recuperation_Error:
MsgBox "(Erreur n°" & ERR.Number & ") " & ERR.Description
RESEXE.ERR = ERR.Description
FLGERR = True
End Sub
Et donc, sur cette ligne,
ss_rst.Open ss_cmd
,
j'ai droit au message "Syntax Error" !
Donc voilà, si quelqu'un à une petite idée, elle est la bienvenue :)
Et juste une petite précision, j'ai l'impression que mes fonctions CInt ne convertissent pas ma chaine en integer, donc peut-être mon problème viendrait-il de la ?
Je m'étais basé sur une procédure trouvé sur un tuto sur le net, mais je pense que cette partie ne devait pas être bonne, ou alors je l'utilise mal ??!
GarnierFlorian
Messages postés129Date d'inscriptionmardi 27 mai 2008StatutMembreDernière intervention26 juillet 2011 12 nov. 2010 à 11:42
Bon, ba ça marche ?!?!
Je ne sais pas trop pourquoi ça ne marchait pas avant :
Sub Recuperation()
Dim ss_cmd As ADODB.Command
Dim ss_parmoi As ADODB.Parameter
Dim ss_parann As ADODB.Parameter
Dim ss_rst As ADODB.Recordset
On Error GoTo Recuperation_Error
Connexion
If FLGCNX = True Then
RESEXE.X = 13
RESEXE.Y = 3
'On déclare la command
Set ss_cmd = New ADODB.Command
With ss_cmd
.ActiveConnection = CNXFOX
.CommandType = adCmdText
.NamedParameters = True
End With
Set ss_parmoi = New ADODB.Parameter
Set ss_parann = New ADODB.Parameter
With ss_parmoi
.Direction = adParamInputOutput
.Type = adInteger
.Name = "ChoixMois"
End With
With ss_parann
.Direction = adParamInputOutput
.Type = adInteger
.Name = "ChoixAnnee"
End With
ss_cmd.Parameters.Append ss_parmoi
ss_cmd.Parameters.Append ss_parann
ss_parmoi.Value = CInt(RPT.MOI)
ss_parann.Value = CInt(RPT.ANN)
RESEXE.REQRPT = "SELECT DISTINCT pays.nompay,COUNT(client.numctr) AS nbprospect" & _
" FROM pays,client" & _
" WHERE client.codpay = pays.codpay" & _
" AND flgprp = 1" & _
" AND MONTH(client.datcre) = " & ss_parmoi & _
" AND YEAR(client.datcre) = " & ss_parann & _
" GROUP BY pays.nompay" & _
" ORDER BY pays.nompay"
' "
ss_cmd.CommandText = RESEXE.REQRPT
'On déclare le recordset
Set ss_rst = New ADODB.Recordset
'Exécute la requête
With ss_rst
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
End With
ss_rst.Open ss_cmd
ss_rst.Close
Set ss_cmd = Nothing
Set ss_rst = Nothing
End If
Deconnexion
On Error GoTo 0
Exit Sub
Recuperation_Error:
MsgBox "(Erreur n°" & ERR.Number & ") " & ERR.Description
RESEXE.ERR = ERR.Description
FLGERR = True
End Sub