ADO+Recordset

Résolu
cs_miss_poopoucy Messages postés 22 Date d'inscription mercredi 6 juin 2007 Statut Membre Dernière intervention 23 juin 2011 - 23 juin 2008 à 11:28
misafredo Messages postés 12 Date d'inscription samedi 17 mars 2007 Statut Membre Dernière intervention 19 juillet 2011 - 30 juin 2008 à 09:54
salut,
je cherche a importer des données depuis deux différentes msflexgrid vers ma bdd dans les ùmemes tables,et j'ai un msg d'erreur "Les arguments sont de type incorrect, en dehors des limites autorisées ou en conflit les uns avec les autres".
???????
j'ai essayé de travailler avec deux connexions mais sans resultat...

voila mon code:
Dim ct As ADODB.Connection
Dim rc_clt As ADODB.Recordset
Dim rc_ab As ADODB.Recordset
Dim rc_mt As ADODB.Recordset

Dim i, j, pos, ini, mrows, srows As Integer
Dim c As String

'*********************OUVERTURE DES TABLES*******************
'****************EXTRACTION DES DONNEES****************
'************MT*********************
Private Sub facture_mt()
Set rc_mt = New ADODB.Recordset
rc_mt.Open "Facture_MT", ct, adOpenDynamic, adLockOptimistic

    rc_mt.AddNew
    rc_mt!Abonnement_Police = Me.mt.TextMatrix(i, 4)
    rc_mt!MONTANT_A_REGLER = Me.mt.TextMatrix(i, 6)
    rc_mt!DATE_FACTURE = Me.mt.TextMatrix(i, 8)
    rc_mt!DATE_REGLEMENT = Me.mt.TextMatrix(i, 9)
    rc_mt!reglé = Me.mt.TextMatrix(i, 7)
    rc_mt.Update

End Sub
Private Sub ab()
Set rc_ab = New ADODB.Recordset
rc_ab.Open "Abonnement", ct, adOpenDynamic, adLockOptimistic

    rc_ab.AddNew
    rc_ab!POLICE = frm_import.mt.TextMatrix(i, 4)
    rc_ab!Client_MT_CIN_Identifiant = frm_import.mt.TextMatrix(i, 0)
    rc_ab!Commune_Id_commune = frm_import.mt.TextMatrix(i, 10)
    rc_ab!DATE_ABONNEMENT = Me.mt.TextMatrix(i, 5)
    rc_ab.Update

End Sub

Private Sub clt()
Set rc_clt = New ADODB.Recordset
rc_clt.Open "Client_MT", ct, adOpenDynamic, adLockOptimistic

    rc_clt.AddNew
    rc_clt!CIN_IDENTIFIANT = frm_import.mt.TextMatrix(i, 0)
    rc_clt!NOM_RAISON_SOCIALE = frm_import.mt.TextMatrix(i, 1)
    rc_clt!ADRESSE = frm_import.mt.TextMatrix(i, 2)
    rc_clt!VILLE = frm_import.mt.TextMatrix(i, 3)
    rc_clt.Update

End Sub

'****************SAP******************
Sub facture_sap()
Set rc_sap = New ADODB.Recordset
rc_sap.Open "Facture_SAP", ct, adOpenDynamic, adLockOptimistic

    rc_sap.AddNew
    rc_sap!Abonnement_Police = Me.sap.TextMatrix(i, 4)
    rc_sap!MONTANT_A_REGLER = Me.sap.TextMatrix(i, 6)
    rc_sap!DATE_FACTURE = Me.sap.TextMatrix(i, 8)
    rc_sap!DATE_REGLEMENT = Me.sap.TextMatrix(i, 9)
    rc_sap!reglé = Me.sap.TextMatrix(i, 7)
    rc_sap.Update

End Sub
Sub ab_sap()
Set rc_ab = New ADODB.Recordset
rc_ab.Open "Abonnement", ct, adOpenDynamic, adLockOptimistic

 
    rc_ab.AddNew
    rc_ab!POLICE = Me.sap.TextMatrix(i, 4)
    rc_ab!Client_MT_CIN_Identifiant = Me.sap.TextMatrix(i, 0)
    rc_ab!Commune_Id_commune = Me.sap.TextMatrix(i, 10)
    rc_ab!DATE_ABONNEMENT = Me.sap.TextMatrix(i, 5)
    rc_ab.Update

End Sub

Sub clt_sap()
Set rc_clt = New ADODB.Recordset
rc_clt.Open "Client_MT", ct, adOpenDynamic, adLockOptimistic

    rc_clt.AddNew
    rc_clt!CIN_IDENTIFIANT = Me.sap.TextMatrix(i, 0)
    rc_clt!NOM_RAISON_SOCIALE = Me.sap.TextMatrix(i, 1)
    rc_clt!ADRESSE = Me.sap.TextMatrix(i, 2)
    rc_clt!VILLE = Me.sap.TextMatrix(i, 3)
    rc_clt.Update

End Sub

Private Sub cmd_bdd_Click()

mrows = frm_import.mt.Rows
srows = frm_importsap.sap.Rows
j = 1
i = 1
Do While i <= mrows

    Call ab
    Call clt
    Call facture_mt
    i = i + 1
Loop

i = i + 1
Do While j <= srows
    Call ab_sap
    Call clt_sap
    Call facture_sap
    j = j + 1
Loop

End Sub

Private Sub Form_Load()

'****************BASE DE DONNEES***********************

Set ct = New ADODB.Connection
ct.Provider = "microsoft.jet.oledb.4.0"
ct.ConnectionString = "C:\prj_stage\rapprochement_mt.mdb"
ct.Open
End Sub

miss poopoucy
A voir également:

15 réponses

cs_miss_poopoucy Messages postés 22 Date d'inscription mercredi 6 juin 2007 Statut Membre Dernière intervention 23 juin 2011
23 juin 2008 à 15:07
c bon c reglé j'ai travaillé avec la meme connexion mais dans deux differents formulaire selon MT et SAP.
merci pr l'aide.
youpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

miss poopoucy
3
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
23 juin 2008 à 12:38
Salut
Où se produit cette erreur ? Sur quelle ligne ?

A vu de nez, je vois ceci :
   rc_mt.Open "Facture_MT", ct, adOpenDynamic, adLockOptimistic
Ceci n'est pas une syntaxe correcte : Il manque la requète SQL.
On devrait y voir qqchose du genre :
   rc_mt.Open "Select * From Facture_MT", ct, adOpenDynamic, adLockOptimistic
en supposant que Facture_MT est le nom de ta table

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

<hr />Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
0
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
23 juin 2008 à 12:51
Si tu dois ajouter des enregistrements à ta DB, il serait plus sage de passer par les instructions SQL adéquat, genre :
   
   Dim SQL As String
   Dim Result As Long
   SQL = "Insert Into maTable " & _
         "Select [Abonnement_Police] = '" & Me.mt.TextMatrix(i,  4) & "', " & _
         "       [MONTANT_A_REGLER]  = "  & Me.sap.TextMatrix(i, 6) & ", " & _
         "       [DATE_FACTURE]      = #" & Me.sap.TextMatrix(i, 8) & "#, " & _
         "       [DATE_REGLEMENT]    = #" & Me.sap.TextMatrix(i, 9) & "#, " & _
         "       [reglé]             = '" & Me.sap.TextMatrix(i, 7) & "'"
   ct.Execute SQL, Result
   MsgBox CStr(Result) & " enregistrement ajouté"
   ...

en respectant les règles de la syntaxe SQL :
Si le champ de ta DB est :
- Texte : Encadrer le contenu avec des '
- Numérique : pas d'encadrement
- Date : Encadrer le contenu avec des #
Si le nom du champ comporte des caractères spéciaux (espaces, accents, _ ...), encadrer le nom du champ par des crochets droits [ et ]

Tu trouveras des détails dans n'importe quelle source du site qui parle de RecordSet sous ADODB.

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

<hr />Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
0
cs_miss_poopoucy Messages postés 22 Date d'inscription mercredi 6 juin 2007 Statut Membre Dernière intervention 23 juin 2011
23 juin 2008 à 12:54
la systaxe est correcte j'en suis sûre!
deja ce code permet juste d'importer les données relatives a la partie MT.
mais aparemment ya un conflit d'utilisation de recordset, comme vous voyez j'utilise le meme rc pr l'extraction depuis deux differents objets et pour insérer dans les meme tables.
miss poopoucy
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
lillith212 Messages postés 1229 Date d'inscription vendredi 16 novembre 2007 Statut Membre Dernière intervention 16 juin 2009
23 juin 2008 à 13:52
Salut,
Je viens de regarder ton code et une chose m'interpelle. Tu utilises tes rs mais tu ne les ferme jamais afin de les décharger completement avant de t'en reservir et ca meme si tu utilise la meme déclaration.

*********************************
Dim ct As ADODB.Connection
Dim rc_clt As ADODB.Recordset
Dim rc_ab As ADODB.Recordset
Dim rc_mt As ADODB.Recordset

Dim i, j, pos, ini, mrows, srows As Integer
Dim c As String

'*********************OUVERTURE DES TABLES*******************
'****************EXTRACTION DES DONNEES****************
'************MT*********************
Private Sub facture_mt()
Set rc_mt = New ADODB.Recordset
rc_mt.Open "Facture_MT", ct, adOpenDynamic, adLockOptimistic

    rc_mt.AddNew
    rc_mt!Abonnement_Police = Me.mt.TextMatrix(i, 4)
    rc_mt!MONTANT_A_REGLER = Me.mt.TextMatrix(i, 6)
    rc_mt!DATE_FACTURE = Me.mt.TextMatrix(i, 8)
    rc_mt!DATE_REGLEMENT = Me.mt.TextMatrix(i, 9)
    rc_mt!reglé = Me.mt.TextMatrix(i, 7)
    rc_mt.Update
    rs_mt.Close
    Set rs_mt = Nothing

End Sub
Private Sub ab()
Set rc_ab = New ADODB.Recordset
rc_ab.Open "Abonnement", ct, adOpenDynamic, adLockOptimistic

    rc_ab.AddNew
    rc_ab!POLICE = frm_import.mt.TextMatrix(i, 4)
    rc_ab!Client_MT_CIN_Identifiant = frm_import.mt.TextMatrix(i, 0)
    rc_ab!Commune_Id_commune = frm_import.mt.TextMatrix(i, 10)
    rc_ab!DATE_ABONNEMENT = Me.mt.TextMatrix(i, 5)
    rc_ab.Update
    rs_ab.Close
    Set rs_ab = Nothing
End Sub

Private Sub clt()
Set rc_clt = New ADODB.Recordset
rc_clt.Open "Client_MT", ct, adOpenDynamic, adLockOptimistic

    rc_clt.AddNew
    rc_clt!CIN_IDENTIFIANT = frm_import.mt.TextMatrix(i, 0)
    rc_clt!NOM_RAISON_SOCIALE = frm_import.mt.TextMatrix(i, 1)
    rc_clt!ADRESSE = frm_import.mt.TextMatrix(i, 2)
    rc_clt!VILLE = frm_import.mt.TextMatrix(i, 3)
    rc_clt.Update
    rs_clt.Close
    Set rs_clt= Nothing

End Sub

'****************SAP******************
Sub facture_sap()
Set rc_sap = New ADODB.Recordset
rc_sap.Open "Facture_SAP", ct, adOpenDynamic, adLockOptimistic

    rc_sap.AddNew
    rc_sap!Abonnement_Police = Me.sap.TextMatrix(i, 4)
    rc_sap!MONTANT_A_REGLER = Me.sap.TextMatrix(i, 6)
    rc_sap!DATE_FACTURE = Me.sap.TextMatrix(i, 8)
    rc_sap!DATE_REGLEMENT = Me.sap.TextMatrix(i, 9)
    rc_sap!reglé = Me.sap.TextMatrix(i, 7)
    rc_sap.Update
    rs_sap.Close
    Set rs_sap = Nothing

End Sub
Sub ab_sap()
Set rc_ab = New ADODB.Recordset
rc_ab.Open "Abonnement", ct, adOpenDynamic, adLockOptimistic

 
    rc_ab.AddNew
    rc_ab!POLICE = Me.sap.TextMatrix(i, 4)
    rc_ab!Client_MT_CIN_Identifiant = Me.sap.TextMatrix(i, 0)
    rc_ab!Commune_Id_commune = Me.sap.TextMatrix(i, 10)
    rc_ab!DATE_ABONNEMENT = Me.sap.TextMatrix(i, 5)
    rc_ab.Update
    rs_ab.Close
    Set rs_ab = Nothing

End Sub

Sub clt_sap()
Set rc_clt = New ADODB.Recordset
rc_clt.Open "Client_MT", ct, adOpenDynamic, adLockOptimistic

    rc_clt.AddNew
    rc_clt!CIN_IDENTIFIANT = Me.sap.TextMatrix(i, 0)
    rc_clt!NOM_RAISON_SOCIALE = Me.sap.TextMatrix(i, 1)
    rc_clt!ADRESSE = Me.sap.TextMatrix(i, 2)
    rc_clt!VILLE = Me.sap.TextMatrix(i, 3)
    rc_clt.Update
    rs_clt.Close
    Set rs_clt = Nothing

End Sub

Private Sub cmd_bdd_Click()

mrows = frm_import.mt.Rows
srows = frm_importsap.sap.Rows
j = 1
i = 1
Do While i <= mrows

    Call ab
    Call clt
    Call facture_mt
    i = i + 1
Loop

i = i + 1
Do While j <= srows
    Call ab_sap
    Call clt_sap
    Call facture_sap
    j = j + 1
Loop

End Sub

Private Sub Form_Load()

'****************BASE DE DONNEES***********************

Set ct = New ADODB.Connection
ct.Provider = "microsoft.jet.oledb.4.0"
ct.ConnectionString = "C:\prj_stage\rapprochement_mt.mdb"
ct.Open
End Sub

**************************************************

Voila moi ou je trouve que ca coince...
Bon courage

S.L.B.
<hr />
0
cs_miss_poopoucy Messages postés 22 Date d'inscription mercredi 6 juin 2007 Statut Membre Dernière intervention 23 juin 2011
23 juin 2008 à 14:11
merci pr ta solution je l'ai essayé mais ça marche tjrs pas ça ne ramene que les enregistrement MT.

miss poopoucy
0
lillith212 Messages postés 1229 Date d'inscription vendredi 16 novembre 2007 Statut Membre Dernière intervention 16 juin 2009
23 juin 2008 à 14:21
Re:

Dans le pas à pas... il passe bien dans chaque procédure?

S.L.B.
<hr />
0
lillith212 Messages postés 1229 Date d'inscription vendredi 16 novembre 2007 Statut Membre Dernière intervention 16 juin 2009
23 juin 2008 à 15:11
N'oubli pas de valider
Contente que tu ais trouvé ta solution...

S.L.B.
<hr />
0
cs_miss_poopoucy Messages postés 22 Date d'inscription mercredi 6 juin 2007 Statut Membre Dernière intervention 23 juin 2011
23 juin 2008 à 15:17
en fait je fais comment si je souhaite aider les autres et proposer mes solutions......??

miss poopoucy
0
lillith212 Messages postés 1229 Date d'inscription vendredi 16 novembre 2007 Statut Membre Dernière intervention 16 juin 2009
23 juin 2008 à 15:24
tu réponds sur le forum tout simplement

S.L.B.
<hr />
0
lillith212 Messages postés 1229 Date d'inscription vendredi 16 novembre 2007 Statut Membre Dernière intervention 16 juin 2009
23 juin 2008 à 15:24
tu réponds sur le forum tout simplement
ou tu postes des codes sources ou des tutoriaux
S.L.B.
<hr />
0
cs_miss_poopoucy Messages postés 22 Date d'inscription mercredi 6 juin 2007 Statut Membre Dernière intervention 23 juin 2011
23 juin 2008 à 23:42
Saluut,
me voila de retour!!j'ai besoin de comparer 2 recordset (facture_mt et facture_sap)selon le nombre de lignes et selon un champs donné(reglé), et afficher le resultat dans une msflexgrid par exemple.
je sais pas comment procéder, j'ai pensé a utiliser une requête de jointure mais c tjrs flou ds ma tete!si klk1 pouvait m'aider ça serait gentiiiiiiiiiiiiiiiiiil
mircééé!
miss poopoucy
0
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
24 juin 2008 à 12:30
Salut
Pose ta nouvelle question dans un nouveau post sur le forum.
Donne bien tous les détails afin qu'on comprenne ton environnement et ce que tu veux faire.
Pense aussi à lire quelques sources sur ce sujet, elles sont riches en enseignement.

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

<hr />Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
0
cs_miss_poopoucy Messages postés 22 Date d'inscription mercredi 6 juin 2007 Statut Membre Dernière intervention 23 juin 2011
24 juin 2008 à 12:42
voila mon code:
Dim ct As ADODB.Connection
Dim rc_clt As ADODB.Recordset
Dim rc_ab As ADODB.Recordset
Dim rc_mt As ADODB.Recordset

Dim i, j, pos, ini, mrows, srows As Integer
Dim c As String

'*********************OUVERTURE DES TABLES*******************
'****************EXTRACTION DES DONNEES****************
'************MT*********************
Private Sub facture_mt()
Set rc_mt = New ADODB.Recordset
rc_mt.Open "Facture_MT", ct, adOpenDynamic, adLockOptimistic

    rc_mt.AddNew
    rc_mt!Abonnement_Police = Me.mt.TextMatrix(i, 4)
    rc_mt!MONTANT_A_REGLER = Me.mt.TextMatrix(i, 6)
    rc_mt!DATE_FACTURE = Me.mt.TextMatrix(i, 8)
    rc_mt!DATE_REGLEMENT = Me.mt.TextMatrix(i, 9)
    rc_mt!reglé = Me.mt.TextMatrix(i, 7)
    rc_mt.Update

End Sub
Private Sub ab()
Set rc_ab = New ADODB.Recordset
rc_ab.Open "Abonnement", ct, adOpenDynamic, adLockOptimistic

    rc_ab.AddNew
    rc_ab!POLICE = frm_import.mt.TextMatrix(i, 4)
    rc_ab!Client_MT_CIN_Identifiant = frm_import.mt.TextMatrix(i, 0)
    rc_ab!Commune_Id_commune = frm_import.mt.TextMatrix(i, 10)
    rc_ab!DATE_ABONNEMENT = Me.mt.TextMatrix(i, 5)
    rc_ab.Update

End Sub

Private Sub clt()
Set rc_clt = New ADODB.Recordset
rc_clt.Open "Client_MT", ct, adOpenDynamic, adLockOptimistic

    rc_clt.AddNew
    rc_clt!CIN_IDENTIFIANT = frm_import.mt.TextMatrix(i, 0)
    rc_clt!NOM_RAISON_SOCIALE = frm_import.mt.TextMatrix(i, 1)
    rc_clt!ADRESSE = frm_import.mt.TextMatrix(i, 2)
    rc_clt!VILLE = frm_import.mt.TextMatrix(i, 3)
    rc_clt.Update

End Sub

'****************SAP******************
Sub facture_sap()
Set rc_sap = New ADODB.Recordset
rc_sap.Open "Facture_SAP", ct, adOpenDynamic, adLockOptimistic

    rc_sap.AddNew
    rc_sap!Abonnement_Police = Me.sap.TextMatrix(i, 4)
    rc_sap!MONTANT_A_REGLER = Me.sap.TextMatrix(i, 6)
    rc_sap!DATE_FACTURE = Me.sap.TextMatrix(i, 8)
    rc_sap!DATE_REGLEMENT = Me.sap.TextMatrix(i, 9)
    rc_sap!reglé = Me.sap.TextMatrix(i, 7)
    rc_sap.Update

End Sub
Sub ab_sap()
Set rc_ab = New ADODB.Recordset
rc_ab.Open "Abonnement", ct, adOpenDynamic, adLockOptimistic

 
    rc_ab.AddNew
    rc_ab!POLICE = Me.sap.TextMatrix(i, 4)
    rc_ab!Client_MT_CIN_Identifiant = Me.sap.TextMatrix(i, 0)
    rc_ab!Commune_Id_commune = Me.sap.TextMatrix(i, 10)
    rc_ab!DATE_ABONNEMENT = Me.sap.TextMatrix(i, 5)
    rc_ab.Update

End Sub

Sub clt_sap()
Set rc_clt = New ADODB.Recordset
rc_clt.Open "Client_MT", ct, adOpenDynamic, adLockOptimistic

    rc_clt.AddNew
    rc_clt!CIN_IDENTIFIANT = Me.sap.TextMatrix(i, 0)
    rc_clt!NOM_RAISON_SOCIALE = Me.sap.TextMatrix(i, 1)
    rc_clt!ADRESSE = Me.sap.TextMatrix(i, 2)
    rc_clt!VILLE = Me.sap.TextMatrix(i, 3)
    rc_clt.Update

End Sub

Private Sub cmd_bdd_Click()

mrows = frm_import.mt.Rows
srows = frm_importsap.sap.Rows
j = 1
i = 1
Do While i <= mrows

    Call ab
    Call clt
    Call facture_mt
    i = i + 1
Loop

i = i + 1
Do While j <= srows
    Call ab_sap
    Call clt_sap
    Call facture_sap
    j = j + 1
Loop

End Sub

Private Sub Form_Load()

'****************BASE DE DONNEES***********************

Set ct = New ADODB.Connection
ct.Provider = "microsoft.jet.oledb.4.0"
ct.ConnectionString = "C:\prj_stage\rapprochement_mt.mdb"
ct.Open
End Sub

miss poopoucy
0
misafredo Messages postés 12 Date d'inscription samedi 17 mars 2007 Statut Membre Dernière intervention 19 juillet 2011
30 juin 2008 à 09:54
Bonjour,
 j'ai selectionné des champs ou des enregistrements evec une table,si la table est a 10 champs il n'y a pas de probleme mais si j'ai essaié avec un autre table a 127 champs il y a une erreur comme "requête est tres complexe  "

 Set CnAccess = New ADODB.Connection
    CnAccess.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & Form1.Dialog_Sible.FileName
    CnAccess.Open

Set RsAccess = New ADODB.Recordset
Dim CriterFiltreProd_B(0 To 200) As String
.........



  With Form1
            For i = 0 To .List6.ListCount - 1
            If Not IsNull(RsAccessA(i)) Then
                CriterFiltreProd_B(i) = RsAccessA(i)
                Else
                CriterFiltreProd_B(i) = ""
                End If
            Next i
                SQLB = "SELECT [" & .List6.List(0) & "]"
            If .List6.ListCount > 1 Then
                 For i = 1 To .List6.ListCount - 1
        SQLB = SQLB & ",[" & .List6.List(i) & "]"
           Next i
           End If
        SQLB = SQLB & " FROM " & Nom_Table_Desti & " WHERE ("
       
        SQLB = SQLB & "([" & .List6.List(0) & "]= '" & CriterFiltreProd_B(0) & "')"
       
        If .List6.ListCount > 1 Then
           For i = 1 To .List6.ListCount - 1
        SQLB = SQLB & "And ([" & .List6.List(i) & "]= '" & CriterFiltreProd_B(i) & "')"
        Next i
        End If
        SQLB = SQLB & ")"
                      SQLB = SQLB & " ORDER BY "
           If .List6.ListCount > 1 Then
           For i = 1 To .List6.ListCount - 1
           SQLB = SQLB & "[" & .List6.List(i) & "],"
           Next i
           End If
           SQLB = SQLB & "[" & .List6.List(0) & "];"
    End With
               
    RsAccess.Open SQLB, CnAccess, adOpenDynamic, adLockPessimistic

Aide mois s'il vous plais
merci d'avance






 
0
Rejoignez-nous