Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Access > VBA Access
VBA Access Le forum pour les questions relatives au code VBA sous Access, et à son environnement de développement VBE.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 02/08/2011, 09h23   #1
Futur Membre du Club
 
Homme
Inscription : juillet 2011
Messages : 77
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : juillet 2011
Messages : 77
Points : 18
Points : 18
Par défaut Erreur: Trop peu de paramétres : 1 attendu

bonjour,
a l'execution de mon bouton qui envoie les valeurs d'une requete à un fichier excell je recoi l'erreur suivante :
trop peu de paramétres: 1 attendu.
Sachant que la requete contient les champs de deux tables reliées entre eux.
voila un bout de mon code :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Dim oAppExcel As Excel.Application
Dim oXLWB As Excel.Workbook
Dim oXLSh As Excel.Worksheet
Dim oXLRng As Excel.Range
Dim oRST As DAO.Recordset
Dim C As Integer
    'Zéro décalage au départ
    C = -1
    Set oAppExcel = CreateObject("Excel.Application")
    Set oRST = CurrentDb.OpenRecordset("MaRequete)
    With oAppExcel
        .DisplayAlerts = False
        Set oXLWB = .Workbooks.Open("C:\Chemin\Monfichier.xls")
        With oXLWB
            Set oXLSht = .Worksheets("Feuilles2")
            With oXLSht
                Set oXLRng = .Range("B4")
                With oXLRng
                    .Select
                    With oRST
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
               Set oXLRng = Nothing
    Set oXLSht = Nothing
 
    Set oAppExcel = Nothing
    Set oRST = Nothing
             Set oXLWB = Nothing
            .SaveAs "C:\Chemin\MonFichier.xls"
            .Close False
        End With
        .Quit
    End With
tissam89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/08/2011, 10h09   #2
Membre du Club
 
Inscription : juin 2009
Messages : 86
Détails du profil
Informations forums :
Inscription : juin 2009
Messages : 86
Points : 59
Points : 59
bonjour

à quelle ligne de code le programme t'affiche l'erreur ?
si tu lances ta requête manuellement, ça fonctionne ?
Begon0 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/08/2011, 10h25   #3
Futur Membre du Club
 
Homme
Inscription : juillet 2011
Messages : 77
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : juillet 2011
Messages : 77
Points : 18
Points : 18
c'est à cette ligne qu'il affiche l'erreur :
Code :
Set oRST = CurrentDb.OpenRecordset("Marequete")
oui manuellement la requête marche tres bien.par contre l'execution de la requete demande une valeur lors de lancement,parcequ'elle fait des calculs deriere.

voila le code sql de ma requete:

Code :
1
2
3
SELECT Feuil2.[Code Pays], Feuil2.Pays, Feuil2.[Nb Total ], [Bilan].[Nb]
FROM [Bilan] INNER JOIN Feuil2 ON [Bilan].Pays = Feuil2.Pays
WHERE (((Feuil2.Pays)="France" Or (Feuil2.Pays)="Allemagne" Or (Feuil2.Pays)="Suisse" Or (Feuil2.Pays)="Belgique" ))ORDER BY Feuil2.Pays;
tissam89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/08/2011, 13h00   #4
Futur Membre du Club
 
Homme
Inscription : juillet 2011
Messages : 77
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : juillet 2011
Messages : 77
Points : 18
Points : 18
L'erreur c'est tres peu de parametres.desolé
tissam89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/08/2011, 13h44   #5
Futur Membre du Club
 
Homme
Inscription : juillet 2011
Messages : 77
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : juillet 2011
Messages : 77
Points : 18
Points : 18
Voile mes nouveaux modifications(Ajouts).Ca marche tres bien.

Code :
1
2
3
4
Dim req As DAO.QueryDef    
       Set req = CurrentDb.QueryDefs("Marequete")
    req.Parameters("Valeur") = 7
        Set oRST = req.OpenRecordset()
Mais j'ai ecri la valeur 7 dans le code.moi je veux donner le choix à l'utilisateur.
tissam89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/08/2011, 14h42   #6
Membre du Club
 
Inscription : juin 2009
Messages : 86
Détails du profil
Informations forums :
Inscription : juin 2009
Messages : 86
Points : 59
Points : 59
utilise la fonction inputbox qui te permettra de récupérer la valeur saisie par l'utilisateur et passe la dans le paramètre de ta requete
Begon0 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/08/2011, 11h01   #7
Futur Membre du Club
 
Homme
Inscription : juillet 2011
Messages : 77
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : juillet 2011
Messages : 77
Points : 18
Points : 18
Merci ! moi j ai mi à la place de 7 une valeur stocké dans une table.
maintenant j'ai ecri mon code qui marche tres bien pour copier une requete dans une feuille.mais quand je veux copier d'autres requetes sur d autre feuilles,avec le meme code ne marche pas.je trouve que c un peu bizard.
Je vous poste mon code qui marche bien lorsqu'il est seul:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Private Sub Pilote_Click()
Dim oAppExcel                                          As Excel.Application
Dim oXLWB                                              As Excel.Workbook
Dim oXLSht                                             As Excel.Worksheet
Dim oXLRng                                             As Excel.Range
Dim oRST                                               As DAO.Recordset
Dim F3                                               As DAO.Recordset
Dim req                                                As DAO.QueryDef
Dim ff3                                                 As DAO.QueryDef
Dim C                                                  As Integer
    'Zéro décalage au départ
    C = -1
    Set oAppExcel = CreateObject("Excel.Application")
     Set Lien = CurrentDb.OpenRecordset("Lien")
    Lien.MoveFirst
    While Not Lien.EOF
    With Lien
        LienExcell = .Fields("LienExcell")
        Valeur = .Fields("Valeur")
    End With
    Lien.MoveNext
    Wend
      Set req = CurrentDb.QueryDefs("Feuille2")
      req.Parameters("Delta") = Delta
     Set oRST = req.OpenRecordset()
 
      Set ff3= CurrentDb.QueryDefs("Feuille3")
      ff3.Parameters("valeur") = valeur
     Set  F3 = ff3.OpenRecordset()
 
 
              '________________________________________
     With oAppExcel
        .DisplayAlerts = False
        Set oXLWB = .Workbooks.Open(LienExcell)
        With oXLWB
            Set oXLSht = .Worksheets("Feuille2")
            With oXLSht
                Set oXLRng = .Range("B3")
                With oXLRng
                    .Select
                    With oRST
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            oXLRng.Offset(3, C).Value = .Fields(3).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
            .SaveAs LienExcell
            .Close False
        End With
    Set oXLRng = Nothing
   ' Set oXLSht = Nothing
    Set oAppExcel = Nothing
    Set oRST = Nothing
    .Quit
    End With
 
 End Sub
Mais quand je veux faire le meme travail aux autres requetes avec les autres feuilles ne marche pas.erreur : je vous poste le code

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Dim oAppExcel                                          As Excel.Application
Dim oXLWB                                              As Excel.Workbook
Dim oXLSht                                             As Excel.Worksheet
Dim oXLRng                                             As Excel.Range
Dim oRST                                               As DAO.Recordset
Dim Feuille3                                                 As DAO.Recordset
Dim req                                                As DAO.QueryDef
Dim ff3                                                 As DAO.QueryDef
Dim C                                                  As Integer
    'Zéro décalage au départ
    C = -1
    Set oAppExcel = CreateObject("Excel.Application")
     Set Lien = CurrentDb.OpenRecordset("Lien")
    Lien.MoveFirst
    While Not Lien.EOF
    With Lien
        LienExcell = .Fields("LienExcell")
        Valeur = .Fields("Valeur")
    End With
    Lien.MoveNext
    Wend
      Set req = CurrentDb.QueryDefs("Feuille2")
      req.Parameters("Delta") = Delta
     Set oRST = req.OpenRecordset()
 
      Set ff3= CurrentDb.QueryDefs("Feuille3")
      ff3.Parameters("valeur") = valeur
     Set  F3 = ff3.OpenRecordset()
 
 
              '________________________________________
     With oAppExcel
        .DisplayAlerts = False
        Set oXLWB = .Workbooks.Open(LienExcell)
        With oXLWB
            Set oXLSht = .Worksheets("Feuille2")
            With oXLSht
                Set oXLRng = .Range("B3")
                With oXLRng
                    .Select
                    With oRST
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            oXLRng.Offset(3, C).Value = .Fields(3).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
            .SaveAs LienExcell
            .Close False
        End With
    Set oXLRng = Nothing
   'Set oXLSht = Nothing
    Set oAppExcel = Nothing
    Set oRST = Nothing
    With oXLWB
            Set oXLSht = .Worksheets("Feuille3")
            With oXLSht
                Set oXLRng = .Range("B4")
                With oXLRng
                    .Select
                    With F3
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            oXLRng.Offset(3, C).Value = .Fields(3).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
            .SaveAs LienExcell
            .Close False
        End With
    Set oXLRng = Nothing
    Set oXLSht = Nothing
    Set oAppExcel = Nothing
    Set F3 = Nothing
    .Quit
    End With
 
End Sub
Aidez moi
tissam89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/08/2011, 14h09   #8
Membre du Club
 
Inscription : juin 2009
Messages : 86
Détails du profil
Informations forums :
Inscription : juin 2009
Messages : 86
Points : 59
Points : 59
quel est le message d'erreur et à quel endroit se produit-il ?

as-tu essayé d'enlever la requête qui marchait pour ne laisser que la partie qui ne marche pas pour voir si cela change quelque chose ?
Begon0 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/08/2011, 15h25   #9
Futur Membre du Club
 
Homme
Inscription : juillet 2011
Messages : 77
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : juillet 2011
Messages : 77
Points : 18
Points : 18
tout d'abord je vais vous poster le code en entier que j'ai maintenant:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
Private Sub Feuille2_Click()
Dim oAppExcel                                          As Excel.Application
Dim oXLWB                                              As Excel.Workbook
Dim oXLSht                                             As Excel.Worksheet
Dim oXLRng                                             As Excel.Range
Dim oRST                                               As DAO.Recordset
Dim req                                                As DAO.QueryDef
Dim C                                                  As Integer

    'Zéro décalage au départ
    C = -1
    Set oAppExcel = CreateObject("Excel.Application")
     Set Lien = CurrentDb.OpenRecordset("Lien")
    Lien.MoveFirst
    While Not Lien.EOF
    With Lien
    LienExcell = .Fields("LienExcell")
    Delta = .Fields("Delta")
    End With
    Lien.MoveNext
    Wend
      Set req = CurrentDb.QueryDefs("Pays_Feuilles2")
      req.Parameters("Delta") = Delta
     Set oRST = req.OpenRecordset()

              '________________________________________
     With oAppExcel
        .DisplayAlerts = False
        Set oXLWB = .Workbooks.Open(LienExcell)
        With oXLWB
            Set oXLSht = .Worksheets("Feuille2")
            With oXLSht
            oXLSht.Activate
            
                Set oXLRng = .Range("B3")
                With oXLRng
                    .select
                    With oRST
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            oXLRng.Offset(3, C).Value = .Fields(3).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
            .SaveAs LienExcell
            .Close False
        End With
    Set oXLRng = Nothing
    Set oXLSht = Nothing
    Set oAppExcel = Nothing
    Set oRST = Nothing
    .Quit
    End With
     Call F3
    'Call F4
   
    'Call F5
    'Call F6
    Call F7
    
End Sub


Private Sub F3()
Dim oAppExcel                                          As Excel.Application
Dim oXLWB                                              As Excel.Workbook
Dim oXLSht                                             As Excel.Worksheet
Dim oXLRng                                            As Excel.Range
Dim F3                                                As DAO.Recordset
Dim ff3                                                 As DAO.QueryDef
Dim C                                                  As Integer
    'Zéro décalage au départ
    C = -1
    Set oAppExcel = CreateObject("Excel.Application")
     Set Lien = CurrentDb.OpenRecordset("Lien")
    Lien.MoveFirst
    While Not Lien.EOF
    With Lien
    LienExcell = .Fields("LienExcell")
    Delta = .Fields("Delta")
    End With
    Lien.MoveNext
    Wend
      Set ff3 = CurrentDb.QueryDefs("Pays_Feuilles3")
      ff3.Parameters("Delta") = Delta
      Set F3 = ff3.OpenRecordset()

              '________________________________________
     With oAppExcel
        .DisplayAlerts = False
        Set oXLWB = .Workbooks.Open(LienExcell)
        With oXLWB
            Set oXLSht = .Worksheets("Feuille3")
                      With oXLSht
            oXLSht.Activate
                Set oXLRng = Range("B4")
                With oXLRng
                    .select
                    With F3
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            oXLRng.Offset(3, C).Value = .Fields(3).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
            .SaveAs LienExcell
            .Close False
        End With
    
    Set oXLRng = Nothing
    Set oXLSht = Nothing
    Set oAppExcel = Nothing
    Set F3 = Nothing
    .Quit
    End With

    'Call F7
End Sub

Private Sub F4()
Dim oAppExcel                                          As Excel.Application
Dim oXLWB                                              As Excel.Workbook
Dim oXLSht                                             As Excel.Worksheet
Dim oXLRng                                            As Excel.Range
Dim F4                                                 As DAO.Recordset
Dim ff4                                                As DAO.QueryDef
Dim C                                                  As Integer
    'Zéro décalage au départ
    C = -1
    Set oAppExcel = CreateObject("Excel.Application")
     Set Lien = CurrentDb.OpenRecordset("Lien")
    Lien.MoveFirst
    While Not Lien.EOF
    With Lien
    LienExcell = .Fields("LienExcell")
    Delta = .Fields("Delta")
    End With
    Lien.MoveNext
    Wend
      Set ff4 = CurrentDb.QueryDefs("Pays_Feuilles4")
      ff4.Parameters("Delta") = Delta
      Set F4 = ff4.OpenRecordset()

              '________________________________________
     With oAppExcel
        .DisplayAlerts = False
        Set oXLWB = .Workbooks.Open(LienExcell)
        With oXLWB
            Set oXLSht = .Worksheets("Feuille4")
            'Worksheets("Feuille4").Activate
            oXLSht.Activate
            
            With oXLSht
                Set oXLRng = Range("B3")                With oXLRng
                   .select
                    With F4
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            oXLRng.Offset(3, C).Value = .Fields(3).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
            .SaveAs LienExcell
            .Close False
        End With
    
    Set oXLRng = Nothing
    Set oXLSht = Nothing
    Set oAppExcel = Nothing
    Set F4 = Nothing
  
    .Quit
    End With
    'Call Feuille2_Click
End Sub
Private Sub F5()
Dim oAppExcel                                          As Excel.Application
Dim oXLWB                                              As Excel.Workbook
Dim oXLSht                                              As Excel.Worksheet
Dim oXLRng                                             As Excel.Range
Dim F5                                                As DAO.Recordset
Dim ff5                                                 As DAO.QueryDef
Dim C                                                  As Integer
    'Zéro décalage au départ
    C = -1
    Set oAppExcel = CreateObject("Excel.Application")
     Set Lien = CurrentDb.OpenRecordset("Lien")
    Lien.MoveFirst
    While Not Lien.EOF
    With Lien
    LienExcell = .Fields("LienExcell")
    Delta = .Fields("Delta")
    End With
    Lien.MoveNext
    Wend
      Set ff5 = CurrentDb.QueryDefs("Pays_Feuilles5")
      ff5.Parameters("Delta") = Delta
      Set F5 = ff5.OpenRecordset()

              '________________________________________
     With oAppExcel
        .DisplayAlerts = False
        Set oXLWB = .Workbooks.Open(LienExcell)
        With oXLWB
            Set oXLSht = .Worksheets("Feuille5")
            With oXLSht
            oXLSht.Activate
                Set oXLRng = Range("B3")
                oXLRng.Activate
                
                With oXLRng
                    .select
                    With F5
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            oXLRng.Offset(3, C).Value = .Fields(3).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
            .SaveAs LienExcell
            .Close False
        End With
    
    Set oXLRng = Nothing
    Set oXLSht = Nothing
    Set oAppExcel = Nothing
    Set F5 = Nothing
  
    .Quit
    End With
    'Call Feuille2_Click
End Sub
Private Sub F6()
Dim oAppExcel                                          As Excel.Application
Dim oXLWB                                              As Excel.Workbook
Dim oXLSht                                             As Excel.Worksheet
Dim oXLRng                                            As Excel.Range
Dim F6                                                As DAO.Recordset
Dim ff6                                                 As DAO.QueryDef
Dim C                                                  As Integer
    'Zéro décalage au départ
    C = -1
    Set oAppExcel = CreateObject("Excel.Application")
     Set Lien = CurrentDb.OpenRecordset("Lien")
    Lien.MoveFirst
    While Not Lien.EOF
    With Lien
    LienExcell = .Fields("LienExcell")
    Delta = .Fields("Delta")
    End With
    Lien.MoveNext
    Wend
      Set ff6 = CurrentDb.QueryDefs("Pays_Feuilles6")
      ff6.Parameters("Delta") = Delta
      Set F6 = ff6.OpenRecordset()

              '________________________________________
     With oAppExcel
        .DisplayAlerts = False
        Set oXLWB = .Workbooks.Open(LienExcell)
        With oXLWB
            Set oXLSht = .Worksheets("Feuille6")
           
            With oXLSht
            oXLSht.Activate
                Set oXLRng = Range("B4")
                With oXLRng
                    .select
                    With F6
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            oXLRng.Offset(3, C).Value = .Fields(3).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
            .SaveAs LienExcell
            .Close False
        End With
    
    Set oXLRng = Nothing
    Set oXLSht = Nothing
    Set oAppExcel = Nothing
    Set F6 = Nothing
  
    .Quit
    End With
    'Call Feuille2_Click
End Sub
Private Sub F7()
Dim oAppExcel                                          As Excel.Application
Dim oXLWB                                              As Excel.Workbook
Dim oXLSht                                             As Excel.Worksheet
Dim oXLRng                                             As Excel.Range
Dim F7                                                As DAO.Recordset
Dim ff7                                                 As DAO.QueryDef
Dim C                                                  As Integer
    'Zéro décalage au départ
    C = -1
    Set oAppExcel = CreateObject("Excel.Application")
     Set Lien = CurrentDb.OpenRecordset("Lien")
    Lien.MoveFirst
    While Not Lien.EOF
    With Lien
    LienExcell = .Fields("LienExcell")
    Delta = .Fields("Delta")
    End With
    Lien.MoveNext
    Wend
      Set ff7 = CurrentDb.QueryDefs("Pays_Feuilles7")
      ff7.Parameters("Delta") = Delta
      Set F7 = ff7.OpenRecordset()

              '________________________________________
     With oAppExcel
        .DisplayAlerts = False
        Set oXLWB = .Workbooks.Open(LienExcell)
        With oXLWB
            Set oXLSht = .Worksheets("Feuille7")
           ' Worksheets("Feuille7").Activate
           oXLSht.Activate
            With oXLSht
            oXLSht.Activate
            
                Set oXLRng = Range("B4")
                With oXLRng
                    .select
                    With F7
                        Do While Not .EOF
                            C = C + 1
                            oXLRng.Offset(0, C).Value = .Fields(0).Value
                            oXLRng.Offset(1, C).Value = .Fields(1).Value
                            oXLRng.Offset(2, C).Value = .Fields(2).Value
                            oXLRng.Offset(3, C).Value = .Fields(3).Value
                            .MoveNext
                        Loop
                        .Close
                    End With
 
                End With
            End With
            .SaveAs LienExcell
            .Close False
        End With
    
    Set oXLRng = Nothing
    Set oXLSht = Nothing
    Set oAppExcel = Nothing
    Set F7 = Nothing
  
    .Quit
    End With
    'Call Feuille2_Click
End Sub
oui! quand j execute les deux parties dans des fonctions differente,chacun marche tres bien. maintenant quand je fais les deux dans une seul fonction( pour avoir un seul bouton) ,oubien je fai chacun dans une fonction differente et j'appele l'une des fonctions dans l autre .ça marche avec deux fonctions,mais pour 3 fonctions (quand j'appel deux fonctions dans une ) je recoi l'erreur suivante :

La méthode range de l'objet global a echoué .

je recoi l'erreur dans cette ligne :
Code :
Set oXLRngg = Range("B4")
tissam89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/08/2011, 16h33   #10
Membre du Club
 
Inscription : juin 2009
Messages : 86
Détails du profil
Informations forums :
Inscription : juin 2009
Messages : 86
Points : 59
Points : 59
il manque le point à range :
Code :
1
2
Set oXLRng = .Range("B4")
ta fonction F4 doit aussi avoir un problème sur la ligne :
Code :
1
2
 
Set oXLRng = Range("B3")                With oXLRng
ton .quit ne te génère pas d'erreur ?
tu réaffectes nothing à ta variable oAppExcel et ensuite tu l'utilises encore pour le .quit
je ferais plutot :
Code :
1
2
3
4
 
.quit
end with
Set oAppExcel = Nothing
essaie avec ces corrections et dis moi si c’est mieux
Begon0 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/08/2011, 09h27   #11
Futur Membre du Club
 
Homme
Inscription : juillet 2011
Messages : 77
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : juillet 2011
Messages : 77
Points : 18
Points : 18
Merci pour votre reponse.
j'ai laissé mon code tel qu'il etait ,par contre c'est ici que j'ai fait la modification et ça marchait tres bien:

Code :
1
2
3
   With oXLSht
            oXLSht.Activate
                Set oXLRng = oXLSht.Range("B4")
Il fallait rajouter le oXLSHT avant le Range dans tou le code.
tissam89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/08/2011, 15h24   #12
Membre du Club
 
Inscription : juin 2009
Messages : 86
Détails du profil
Informations forums :
Inscription : juin 2009
Messages : 86
Points : 59
Points : 59
bizarre, il y a pourtant bien le with avant

mais on est plus à une bizarrerie près

n'oublie pas de mettre résolu si tout tes problèmes sont résolu
Begon0 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/08/2011, 09h57   #13
Futur Membre du Club
 
Homme
Inscription : juillet 2011
Messages : 77
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : juillet 2011
Messages : 77
Points : 18
Points : 18
oui c bizarre ^^
Merci pour ton aide et j'ai fait resolu.
tissam89 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 10h09.


 
 
 
 
Partenaires

Hébergement Web