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 05/04/2011, 12h16   #1
Membre du Club
 
Homme Pierrick
Étudiant
Inscription : avril 2011
Messages : 57
Détails du profil
Informations personnelles :
Nom : Homme Pierrick
Localisation : France, Nord (Nord Pas de Calais)

Informations professionnelles :
Activité : Étudiant
Secteur : Industrie

Informations forums :
Inscription : avril 2011
Messages : 57
Points : 45
Points : 45
Par défaut Multiplier le nombre de lignes sous access

Bonjour à tous! (Tout d'abord, désolé de m'être trompé de section tout à l'heure, du coup je reposte ici!!)
Je suis nouveau dans le coin; je me présente vite fait:
Je suis étudiant en DUT GEII (Electricite et Info Industrielle), aujourd'hui en stage jusqu'au 17 juin.
J'ai commencé ce matin: mon objectif: transformer une feuille excel en BD sous access.
Je m'suis donc mis en route. J'ai importé la feuille et tout sa.
Maintenant, j'ai un petit soucis:
Pour chaque enregistrement, j'ai N_debut et N_fin
Au lieu de sa, je voudrais avoir une ligne avec son propre NS(Numero de serie).

En gros, je veux multiplier la ligne XXX fois (avec XXX=N_fin-N_debut) et a chaque fois lui attribuer une colonne NS=NS(d'avant)+1.

J'espère que vous aurez compris!!
PS: j'avais trouvé un code sur le forum qui permettait de faire la meme chose avec des dates, mais impossible de l'adapter, je suis un gros débutant la dessus.

PS2: le code je le met dans un module et j'execute le module c'est bien sa??

Merci à vous, a bientot!
koluche est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/04/2011, 12h50   #2
Rédacteur/Modérateur
 
Avatar de Philippe JOCHMANS
 
Homme Philippe JOCHMANS
Développeur informatique
Inscription : mai 2005
Messages : 17 615
Détails du profil
Informations personnelles :
Nom : Homme Philippe JOCHMANS
Âge : 44
Localisation : France, Loir et Cher (Centre)

Informations professionnelles :
Activité : Développeur informatique
Secteur : Communication - Médias

Informations forums :
Inscription : mai 2005
Messages : 17 615
Points : 30 968
Points : 30 968
Envoyer un message via MSN à Philippe JOCHMANS Envoyer un message via Skype™ à Philippe JOCHMANS
Bonjour

Il ne suffit pas d'importer une feuille Excel sous Access pour créer une base de données.

Je pense que tu as un problème de conception au vu de ta demande.

Il faudrait nous en dire un peu plus.

Philippe
__________________
Détaillez vos questions, sinon vous aurez des réponses erronées et vous irez tout droit dans le et lisez les règles sinon
Si vous pensez commencer sans un livre, oublier : livres pour débuter
Vous pouvez consulter mes articles sur Access et PowerPoint
Le blog Office.

Inutile de m'envoyer un MP pour des questions techniques ou de me relancer , je n'y répondrais pas.
Philippe JOCHMANS est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/04/2011, 13h34   #3
Membre du Club
 
Homme Pierrick
Étudiant
Inscription : avril 2011
Messages : 57
Détails du profil
Informations personnelles :
Nom : Homme Pierrick
Localisation : France, Nord (Nord Pas de Calais)

Informations professionnelles :
Activité : Étudiant
Secteur : Industrie

Informations forums :
Inscription : avril 2011
Messages : 57
Points : 45
Points : 45
Merci de votre réponse. Je vais essayer de détailler un peu:
Je possède un fichier excel. Pour simplifier, on va dire qu'il comporte 3 colonnes:
produit, N_debut et N_fin.
En fait, pour un produit, il y a plusieurs Numeros. Ces numeros sont compris entre N_debut et N_fin. Il y a également une colonne pour la quantité.

J'ai importé ce fichier dans access, je me retrouve avec une table, contenant en colonne "Produit", "N_debut" et "N_fin".

Dans ces colonnes, il y a plusieurs enregistrements.

Petite illustration:
Numero-----------produit------Quantité-----N_debut---------N_fin
(clé primaire)

1--------------Pdt1----------4-----------1001-----------1004
2--------------Pdt2----------2-----------1005-----------1006


Je voudrais en fait avoir ceci:

Numero --------------produit--------------N
(clé primaire)

1--------------Pdt1_1--------------1001
2--------------Pdt1_2--------------1002
3------------- Pdt1_3 --------------1003
4--------------Pdt1_4 --------------1004
5 ------------- Pdt2_1--------------1005
6--------------Pdt2_2--------------1006



Ce serait déja un bon début!
Je pourrais ensuite créer un formulaire pour pouvoir remplir cette table avec de nouvelles entrées ou pour imprimer ces infos!


J'espère avoir été clair.

Encore merci et bon apres-midi!
koluche est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/04/2011, 07h31   #4
Membre Expert
 
Inscription : août 2006
Messages : 1 435
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 1 435
Points : 1 753
Points : 1 753
Bonjour,
il va falloir passer par du code
lire chaque enregistrement de la premiere table et créer les enregistrements de N_debut à N_fin dans une autre table avec une boucle For ... Next
helas est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 11/04/2011, 14h22   #5
Membre du Club
 
Homme Pierrick
Étudiant
Inscription : avril 2011
Messages : 57
Détails du profil
Informations personnelles :
Nom : Homme Pierrick
Localisation : France, Nord (Nord Pas de Calais)

Informations professionnelles :
Activité : Étudiant
Secteur : Industrie

Informations forums :
Inscription : avril 2011
Messages : 57
Points : 45
Points : 45
Rebonjour!
Merci pour votre information.
J'ai fini par arriver a ce 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
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
Function Test()
 
Dim i As Integer
Dim NSV As Integer
Dim Ordre As Integer
Dim Produit As String
Dim Code_Produit As String
Dim Indice As String
Dim N_OF As String
Dim Qte_OF As Integer
Dim Qte_Etiq As Integer
Dim Date_Etiq As Date
Dim Fabricant As String
Dim Compteur As Integer
Dim Fournisseur As String
Dim Remarques As String
Dim RoHS As String
Dim Nom_Fic As String
Dim Notes As String
 
 
 
 
 
 
Dim LISTE_DFC_ENR087 As Recordset
Set LISTE_DFC_ENR087 = CurrentDb.OpenRecordset("LISTE_DFC_ENR087", DB_OPEN_TABLE)
 
Do Until LISTE_DFC_ENR087.EOF = True
 
    i = 1
    Dim temp As Integer
    temp = LISTE_DFC_ENR087("N_Fin") - LISTE_DFC_ENR087("N_Debut")
 
 
 
    If (LISTE_DFC_ENR087("N_Debut")) <> "" Then
    NSV = LISTE_DFC_ENR087("N_Debut")
    End If
    If (LISTE_DFC_ENR087("Ordre")) <> "" Then
    Ordre = LISTE_DFC_ENR087("Ordre")
    End If
    If (LISTE_DFC_ENR087("Produit")) <> "" Then
    Produit = LISTE_DFC_ENR087("Produit")
    End If
    If (LISTE_DFC_ENR087("Code_Produit")) <> "" Then
    Code_Produit = LISTE_DFC_ENR087("Code_Produit")
    End If
    If (LISTE_DFC_ENR087("Indice")) <> "" Then
    Indice = LISTE_DFC_ENR087("Indice")
    End If
    If (LISTE_DFC_ENR087("N_OF")) <> "" Then
    N_OF = LISTE_DFC_ENR087("N_OF")
    End If
    If (LISTE_DFC_ENR087("Quantite dans OF")) <> "" Then
    Qte_OF = LISTE_DFC_ENR087("Quantite dans OF")
    End If
    If (LISTE_DFC_ENR087("Quantité étiquettes à cette date")) <> "" Then
    Qte_Etiq = LISTE_DFC_ENR087("Quantité étiquettes à cette date")
    End If
    If (LISTE_DFC_ENR087("Date_Etiq")) <> "" Then
    Date_Etiq = LISTE_DFC_ENR087("Date_Etiq")
    End If
    If (LISTE_DFC_ENR087("Fabricant")) <> "" Then
    Fabricant = LISTE_DFC_ENR087("Fabricant")
    End If
    If (LISTE_DFC_ENR087("Compteur_Actuel")) <> "" Then
    Compteur = LISTE_DFC_ENR087("Compteur_Actuel")
    End If
    If (LISTE_DFC_ENR087("Fournisseur et _N_BL_CI OU DFV AFFECTE")) <> "" Then
    Fournisseur = LISTE_DFC_ENR087("Fournisseur et _N_BL_CI OU DFV AFFECTE")
    End If
    If (LISTE_DFC_ENR087("Remarques")) <> "" Then
    Remarques = LISTE_DFC_ENR087("Remarques")
    End If
    If (LISTE_DFC_ENR087("RoHS (O / N)")) <> "" Then
    RoHS = LISTE_DFC_ENR087("RoHS (O / N)")
    End If
    If (LISTE_DFC_ENR087("Nom fichier spécial BTW")) <> "" Then
    Nom_Fic = LISTE_DFC_ENR087("Nom fichier spécial BTW")
    End If
    If (LISTE_DFC_ENR087("notes complémentaires (infos)")) <> "" Then
    Notes = LISTE_DFC_ENR087("notes complémentaires (infos)")
    End If
 
     LISTE_DFC_ENR087.Edit
     LISTE_DFC_ENR087("NS") = LISTE_DFC_ENR087("N_Debut")
     LISTE_DFC_ENR087.Update
 
    While i <= temp
 
        LISTE_DFC_ENR087.AddNew
        LISTE_DFC_ENR087("Ordre") = Ordre
        LISTE_DFC_ENR087("Produit") = Produit
        LISTE_DFC_ENR087("Code_Produit") = Code_Produit
        LISTE_DFC_ENR087("Indice") = Indice
        LISTE_DFC_ENR087("N_OF") = N_OF
        LISTE_DFC_ENR087("Quantite dans OF") = Qte_OF
        LISTE_DFC_ENR087("Quantité étiquettes à cette date") = Qte_Etiq
        LISTE_DFC_ENR087("Date_Etiq") = Date_Etiq
        LISTE_DFC_ENR087("Fabricant") = Fabricant
        LISTE_DFC_ENR087("Compteur_Actuel") = Compteur
        LISTE_DFC_ENR087("Fournisseur et _N_BL_CI OU DFV AFFECTE") = Fournisseur
        LISTE_DFC_ENR087("Remarques") = Remarques
        LISTE_DFC_ENR087("RoHS (O / N)") = RoHS
        LISTE_DFC_ENR087("Nom fichier spécial BTW") = Nom_Fic
        LISTE_DFC_ENR087("notes complémentaires (infos)") = Notes
 
        LISTE_DFC_ENR087("NS") = CStr(NSV + 1)
 
        LISTE_DFC_ENR087.Update
        LISTE_DFC_ENR087.MoveNext
        i = i + 1
        NSV = NSV + 1
 
    Wend
 
 
 
   ' For i = 0 To i = temp Step 1
'
      '  LISTE_DFC_ENR087.AddNew
      '  LISTE_DFC_ENR087("NS") = LISTE_DFC_ENR087("N_Debut") + i
      '  LISTE_DFC_ENR087.Update
      '  LISTE_DFC_ENR087.MoveNext
   ' Next i
 
LISTE_DFC_ENR087.MoveNext
Loop
 
 
LISTE_DFC_ENR087.Close
 
 
 
End Function
Cependant, J'ai un autre problème:
Pour la premiere "ligne", Il ajoute les enregistrements juste sous la ligne qu'il est en train de lire, ce qui est parfait. Cependant, arrivé a la deuxieme ligne, il ajoute des enregistrements au dessus de la ligne qu'il lit et au bout de 3 enregistrements sur 50, il bloque, erreur: "l'enregistrement n'existe pas"
Je vais ajouter un screenshot des que j'ai le temps!
auriez vous une idée pour résoudre ce pb?
Merci encore.
Bonne journée.
koluche est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h33.


 
 
 
 
Partenaires

Hébergement Web