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

Recopier Valeurs precedentes

6 réponses
Avatar
Dante Huapaya
J’ai une table avec dont l’information provenant d'un fichier texte m’arrive
comme ca (Malheuresement):

No de compte Date Montant
RZ2565 05/05/2008 258.50
06/05/2008 3255.65
12/07/2008 15.25
30/08/2008 1250.00
RZ1234 01/01/2008 25.65
25/08/2008 1456.65
15/09/2008 125.89
RZ0025 25/05/2007 13.65
01/01/2008 1235.00
15/08/2008 415.30

Alors que moi j’aimerais l’avoir comme ca :

No de compte Date Montant
RZ2565 05/05/2008 258.50
RZ2565 06/05/2008 3255.65
RZ2565 12/07/2008 15.25
RZ2565 30/08/2008 1250.00
RZ1234 01/01/2008 25.65
RZ1234 25/08/2008 1456.65
RZ1234 15/09/2008 125.89
RZ0025 25/05/2007 13.65
RZ0025 01/01/2008 1235.00
RZ0025 15/08/2008 415.30

Merci beaucoup de votre aide

Dante Huapaya

6 réponses

Avatar
Dante Huapaya
Mes excuses pour l'impolitesse:

Bonjour a tous,

"Dante Huapaya" a écrit :

J’ai une table avec dont l’information provenant d'un fichier texte m’arrive
comme ca (Malheuresement):

No de compte Date Montant
RZ2565 05/05/2008 258.50
06/05/2008 3255.65
12/07/2008 15.25
30/08/2008 1250.00
RZ1234 01/01/2008 25.65
25/08/2008 1456.65
15/09/2008 125.89
RZ0025 25/05/2007 13.65
01/01/2008 1235.00
15/08/2008 415.30

Alors que moi j’aimerais l’avoir comme ca :

No de compte Date Montant
RZ2565 05/05/2008 258.50
RZ2565 06/05/2008 3255.65
RZ2565 12/07/2008 15.25
RZ2565 30/08/2008 1250.00
RZ1234 01/01/2008 25.65
RZ1234 25/08/2008 1456.65
RZ1234 15/09/2008 125.89
RZ0025 25/05/2007 13.65
RZ0025 01/01/2008 1235.00
RZ0025 15/08/2008 415.30

Merci beaucoup de votre aide

Dante Huapaya



Avatar
Fabien
Dante Huapaya a écrit :
Mes excuses pour l'impolitesse:

Bonjour a tous,

"Dante Huapaya" a écrit :

J’ai une table avec dont l’information provenant d'un fichier texte m’arrive
comme ca (Malheuresement):

No de compte Date Montant
RZ2565 05/05/2008 258.50
06/05/2008 3255.65
12/07/2008 15.25
30/08/2008 1250.00
RZ1234 01/01/2008 25.65
25/08/2008 1456.65
15/09/2008 125.89
RZ0025 25/05/2007 13.65
01/01/2008 1235.00
15/08/2008 415.30

Alors que moi j’aimerais l’avoir comme ca :

No de compte Date Montant
RZ2565 05/05/2008 258.50
RZ2565 06/05/2008 3255.65
RZ2565 12/07/2008 15.25
RZ2565 30/08/2008 1250.00
RZ1234 01/01/2008 25.65
RZ1234 25/08/2008 1456.65
RZ1234 15/09/2008 125.89
RZ0025 25/05/2007 13.65
RZ0025 01/01/2008 1235.00
RZ0025 15/08/2008 415.30

Merci beaucoup de votre aide

Dante Huapaya





Bonjour,
Public Sub Import_txt2(Nom_Fichier As String, _
Nom_Table As String)
'Pour importer un fichier texte avec tous les champs en mode texte

Dim txtLine As String
Dim F As Integer
Dim I As Integer

Dim Nom_Champs As Variant
Dim Champs As Variant
Dim StrSQl As String
Dim Lchamps As String
Dim Anc_Ref as string
F = FreeFile
Open Nom_Fichier For Input As #F

'On lit la premiére ligne : elle contient les nom des champs
Line Input #F, txtLine
Nom_Champs = Split(txtLine, " ")

'On lit la ligne suivante qui contient des données
Line Input #F, txtLine
Champs = Split(txtLine, " ")
For I = 0 To UBound(Nom_Champs)
Select Case LCase(Nom_Champs(I))
Case "Montant":
'Si Montant vides alors on enregistre Null dans le champs
If Trim(Champs(I)) = "" Then
Lchamps = Lchamps & "Null AS [" & Nom_Champs(I) & "],"
Else
Lchamps = Lchamps & Champs(I) & " AS [" &
Nom_Champs(I) & "],"
End If

Case Else:
If InStr(1, LCase(Nom_Champs(I)), "date") > 0 Then
Lchamps = Lchamps & "cDate('" & Replace(Champs(I),
"-", "/") & "') AS [" & Nom_Champs(I) & "],"
Else
Lchamps = Lchamps & "'" & Replace(Champs(I), "'",
"''") & "' AS [" & Nom_Champs(I) & "],"
End If
End Select
Next I

StrSQl = "SELECT " & Left(Lchamps, Len(Lchamps) - 1) & " INTO [" &
Nom_Table & "];"
CurrentDb.Execute StrSQl 'On créé la nouvelle table
Anc_Ref=Champs(0) 'On mémorise la reférence
'On remplis la table
On Error GoTo erreur
Lchamps = ""
For I = 0 To UBound(Nom_Champs)
Lchamps = Lchamps & "[" & Nom_Champs(I) & "],"
Next I
Lchamps = Left(Lchamps, Len(Lchamps) - 1)
Do While Not EOF(F)
StrSQl = "INSERT INTO [" & Nom_Table & "] (" & Lchamps & ") VALUES ("
Line Input #F, txtLine
Champs = Split(txtLine, " ")
'Si la ligne à 3 éléments : Réf Date et montant
If Ubound(Champs)>2 then
Anc_Ref = Champs(0) ' on reccupere le n° de reference
End if
strsql=strsql & "'" & anc_ref & "'" & Cdate('" & Replace(Champs(0),
"-", "/") & "'), " & "'" & Champs(I) & "); "
CurrentDb.Execute StrSQl
Loop
Close #F
Exit Sub
erreur:
MsgBox "Erreur sur champs N° " & I & " " & Nom_Champs(I) & " " &
Champs(I)
End Sub

@tester
Avatar
Dante Huapaya
Merci,

Mais quand je place la ligne suivante:
strsql=strsql & "'" & anc_ref & "'" & Cdate('" & Replace(Champs(0), _
"-", "/") & "'), " & "'" & Champs(I) & "); "
Elle s'affiche toujour en erreur

Merci

"Fabien" a écrit :

Dante Huapaya a écrit :
> Mes excuses pour l'impolitesse:
>
> Bonjour a tous,
>
> "Dante Huapaya" a écrit :
>
>> J’ai une table avec dont l’information provenant d'un fichier texte m’arrive
>> comme ca (Malheuresement):
>>
>> No de compte Date Montant
>> RZ2565 05/05/2008 258.50
>> 06/05/2008 3255.65
>> 12/07/2008 15.25
>> 30/08/2008 1250.00
>> RZ1234 01/01/2008 25.65
>> 25/08/2008 1456.65
>> 15/09/2008 125.89
>> RZ0025 25/05/2007 13.65
>> 01/01/2008 1235.00
>> 15/08/2008 415.30
>>
>> Alors que moi j’aimerais l’avoir comme ca :
>>
>> No de compte Date Montant
>> RZ2565 05/05/2008 258.50
>> RZ2565 06/05/2008 3255.65
>> RZ2565 12/07/2008 15.25
>> RZ2565 30/08/2008 1250.00
>> RZ1234 01/01/2008 25.65
>> RZ1234 25/08/2008 1456.65
>> RZ1234 15/09/2008 125.89
>> RZ0025 25/05/2007 13.65
>> RZ0025 01/01/2008 1235.00
>> RZ0025 15/08/2008 415.30
>>
>> Merci beaucoup de votre aide
>>
>> Dante Huapaya
>>
Bonjour,
Public Sub Import_txt2(Nom_Fichier As String, _
Nom_Table As String)
'Pour importer un fichier texte avec tous les champs en mode texte

Dim txtLine As String
Dim F As Integer
Dim I As Integer

Dim Nom_Champs As Variant
Dim Champs As Variant
Dim StrSQl As String
Dim Lchamps As String
Dim Anc_Ref as string
F = FreeFile
Open Nom_Fichier For Input As #F

'On lit la premiére ligne : elle contient les nom des champs
Line Input #F, txtLine
Nom_Champs = Split(txtLine, " ")

'On lit la ligne suivante qui contient des données
Line Input #F, txtLine
Champs = Split(txtLine, " ")
For I = 0 To UBound(Nom_Champs)
Select Case LCase(Nom_Champs(I))
Case "Montant":
'Si Montant vides alors on enregistre Null dans le champs
If Trim(Champs(I)) = "" Then
Lchamps = Lchamps & "Null AS [" & Nom_Champs(I) & "],"
Else
Lchamps = Lchamps & Champs(I) & " AS [" &
Nom_Champs(I) & "],"
End If

Case Else:
If InStr(1, LCase(Nom_Champs(I)), "date") > 0 Then
Lchamps = Lchamps & "cDate('" & Replace(Champs(I),
"-", "/") & "') AS [" & Nom_Champs(I) & "],"
Else
Lchamps = Lchamps & "'" & Replace(Champs(I), "'",
"''") & "' AS [" & Nom_Champs(I) & "],"
End If
End Select
Next I

StrSQl = "SELECT " & Left(Lchamps, Len(Lchamps) - 1) & " INTO [" &
Nom_Table & "];"
CurrentDb.Execute StrSQl 'On créé la nouvelle table
Anc_Ref=Champs(0) 'On mémorise la reférence
'On remplis la table
On Error GoTo erreur
Lchamps = ""
For I = 0 To UBound(Nom_Champs)
Lchamps = Lchamps & "[" & Nom_Champs(I) & "],"
Next I
Lchamps = Left(Lchamps, Len(Lchamps) - 1)
Do While Not EOF(F)
StrSQl = "INSERT INTO [" & Nom_Table & "] (" & Lchamps & ") VALUES ("
Line Input #F, txtLine
Champs = Split(txtLine, " ")
'Si la ligne à 3 éléments : Réf Date et montant
If Ubound(Champs)>2 then
Anc_Ref = Champs(0) ' on reccupere le n° de reference
End if
strsql=strsql & "'" & anc_ref & "'" & Cdate('" & Replace(Champs(0),
"-", "/") & "'), " & "'" & Champs(I) & "); "
CurrentDb.Execute StrSQl
Loop
Close #F
Exit Sub
erreur:
MsgBox "Erreur sur champs N° " & I & " " & Nom_Champs(I) & " " &
Champs(I)
End Sub

@tester



Avatar
Michel__D
Bonjour,

"Dante Huapaya" a écrit dans le message de
news:
J’ai une table avec dont l’information provenant d'un fichier texte m’arrive
comme ca (Malheuresement):

No de compte Date Montant
RZ2565 05/05/2008 258.50
06/05/2008 3255.65
12/07/2008 15.25
30/08/2008 1250.00
RZ1234 01/01/2008 25.65
25/08/2008 1456.65
15/09/2008 125.89
RZ0025 25/05/2007 13.65
01/01/2008 1235.00
15/08/2008 415.30

Alors que moi j’aimerais l’avoir comme ca :

No de compte Date Montant
RZ2565 05/05/2008 258.50
RZ2565 06/05/2008 3255.65
RZ2565 12/07/2008 15.25
RZ2565 30/08/2008 1250.00
RZ1234 01/01/2008 25.65
RZ1234 25/08/2008 1456.65
RZ1234 15/09/2008 125.89
RZ0025 25/05/2007 13.65
RZ0025 01/01/2008 1235.00
RZ0025 15/08/2008 415.30

Merci beaucoup de votre aide

Dante Huapaya



Voici une autre alternative (à adapter)

Sub OuvrirDoc()
Dim oW As Object, oDoc As Object, tsCh As Variant
Dim sF As String, sN As String, sT As String, sV As String, sX As String

sT = "LaTable"
sF = "Le_Fichier_Texte.txt"
Set oW = CreateObject("Scripting.FileSystemObject")
Set oDoc = oW.OpenTextFile(sF, 1)
Do While Not oDoc.AtEndOfStream
sV = Trim(oDoc.readline)
If LCase(Right(sV, 7)) = "montant" Then
sX = "CREATE TABLE " & sT & _
" (No_de_compte CHAR(99)" & _
",DateEnr DATE NOT NULL" & _
",Montant MONEY NOT NULL" & _
");"
CurrentDb.Execute sX
sN = ""
Else
tsCh = Split(sV, " ")
If UBound(tsCh) > 2 Then sN = tsCh(0)
sX = "INSERT INTO [" & sT & "] " & _
"([No_de_compte],DateEnr,Montant) " & _
"VALUES ('" & sN & "',#" & _
Format(tsCh(UBound(tsCh) - 1), "mm/dd/yyyy") & "#," & _
tsCh(UBound(tsCh)) & ");"
CurrentDb.Execute sX
End If
Loop
oDoc.Close
Set oDoc = Nothing
Set oW = Nothing
End Sub
Avatar
Dante Huapaya
Merci a tous,
Je vais travailler sur toutes les options.

Bonne journée

Dante

"Michel__D" a écrit :

Bonjour,

"Dante Huapaya" a écrit dans le message de
news:
> J’ai une table avec dont l’information provenant d'un fichier texte m’arrive
> comme ca (Malheuresement):
>
> No de compte Date Montant
> RZ2565 05/05/2008 258.50
> 06/05/2008 3255.65
> 12/07/2008 15.25
> 30/08/2008 1250.00
> RZ1234 01/01/2008 25.65
> 25/08/2008 1456.65
> 15/09/2008 125.89
> RZ0025 25/05/2007 13.65
> 01/01/2008 1235.00
> 15/08/2008 415.30
>
> Alors que moi j’aimerais l’avoir comme ca :
>
> No de compte Date Montant
> RZ2565 05/05/2008 258.50
> RZ2565 06/05/2008 3255.65
> RZ2565 12/07/2008 15.25
> RZ2565 30/08/2008 1250.00
> RZ1234 01/01/2008 25.65
> RZ1234 25/08/2008 1456.65
> RZ1234 15/09/2008 125.89
> RZ0025 25/05/2007 13.65
> RZ0025 01/01/2008 1235.00
> RZ0025 15/08/2008 415.30
>
> Merci beaucoup de votre aide
>
> Dante Huapaya

Voici une autre alternative (à adapter)

Sub OuvrirDoc()
Dim oW As Object, oDoc As Object, tsCh As Variant
Dim sF As String, sN As String, sT As String, sV As String, sX As String

sT = "LaTable"
sF = "Le_Fichier_Texte.txt"
Set oW = CreateObject("Scripting.FileSystemObject")
Set oDoc = oW.OpenTextFile(sF, 1)
Do While Not oDoc.AtEndOfStream
sV = Trim(oDoc.readline)
If LCase(Right(sV, 7)) = "montant" Then
sX = "CREATE TABLE " & sT & _
" (No_de_compte CHAR(99)" & _
",DateEnr DATE NOT NULL" & _
",Montant MONEY NOT NULL" & _
");"
CurrentDb.Execute sX
sN = ""
Else
tsCh = Split(sV, " ")
If UBound(tsCh) > 2 Then sN = tsCh(0)
sX = "INSERT INTO [" & sT & "] " & _
"([No_de_compte],DateEnr,Montant) " & _
"VALUES ('" & sN & "',#" & _
Format(tsCh(UBound(tsCh) - 1), "mm/dd/yyyy") & "#," & _
tsCh(UBound(tsCh)) & ");"
CurrentDb.Execute sX
End If
Loop
oDoc.Close
Set oDoc = Nothing
Set oW = Nothing
End Sub




Avatar
Fabien
Dante Huapaya a écrit :
Merci,

Mais quand je place la ligne suivante:
strsql=strsql & "'" & anc_ref & "'" & Cdate('" & Replace(Champs(0), _
"-", "/") & "'), " & "'" & Champs(I) & "); "
Elle s'affiche toujour en erreur

Merci

"Fabien" a écrit :

Dante Huapaya a écrit :
Mes excuses pour l'impolitesse:

Bonjour a tous,

"Dante Huapaya" a écrit :

J’ai une table avec dont l’information provenant d'un fichier texte m’arrive
comme ca (Malheuresement):

No de compte Date Montant
RZ2565 05/05/2008 258.50
06/05/2008 3255.65
12/07/2008 15.25
30/08/2008 1250.00
RZ1234 01/01/2008 25.65
25/08/2008 1456.65
15/09/2008 125.89
RZ0025 25/05/2007 13.65
01/01/2008 1235.00
15/08/2008 415.30

Alors que moi j’aimerais l’avoir comme ca :

No de compte Date Montant
RZ2565 05/05/2008 258.50
RZ2565 06/05/2008 3255.65
RZ2565 12/07/2008 15.25
RZ2565 30/08/2008 1250.00
RZ1234 01/01/2008 25.65
RZ1234 25/08/2008 1456.65
RZ1234 15/09/2008 125.89
RZ0025 25/05/2007 13.65
RZ0025 01/01/2008 1235.00
RZ0025 15/08/2008 415.30

Merci beaucoup de votre aide

Dante Huapaya





Bonjour,
Public Sub Import_txt2(Nom_Fichier As String, _
Nom_Table As String)
'Pour importer un fichier texte avec tous les champs en mode texte

Dim txtLine As String
Dim F As Integer
Dim I As Integer

Dim Nom_Champs As Variant
Dim Champs As Variant
Dim StrSQl As String
Dim Lchamps As String
Dim Anc_Ref as string
F = FreeFile
Open Nom_Fichier For Input As #F

'On lit la premiére ligne : elle contient les nom des champs
Line Input #F, txtLine
Nom_Champs = Split(txtLine, " ")

'On lit la ligne suivante qui contient des données
Line Input #F, txtLine
Champs = Split(txtLine, " ")
For I = 0 To UBound(Nom_Champs)
Select Case LCase(Nom_Champs(I))
Case "montant":
'Si Montant vides alors on enregistre Null dans le champs
If Trim(Champs(I)) = "" Then
Lchamps = Lchamps & "Null AS [" & Nom_Champs(I) & "],"
Else
Lchamps = Lchamps & Champs(I) & " AS [" &
Nom_Champs(I) & "],"
End If

Case Else:
If InStr(1, LCase(Nom_Champs(I)), "date") > 0 Then
Lchamps = Lchamps & "cDate('" & Replace(Champs(I),
"-", "/") & "') AS [" & Nom_Champs(I) & "],"
Else
Lchamps = Lchamps & "'" & Replace(Champs(I), "'",
"''") & "' AS [" & Nom_Champs(I) & "],"
End If
End Select
Next I

StrSQl = "SELECT " & Left(Lchamps, Len(Lchamps) - 1) & " INTO [" &
Nom_Table & "];"
CurrentDb.Execute StrSQl 'On créé la nouvelle table
Anc_Ref=Champs(0) 'On mémorise la reférence
'On remplis la table
On Error GoTo erreur
Lchamps = ""
For I = 0 To UBound(Nom_Champs)
Lchamps = Lchamps & "[" & Nom_Champs(I) & "],"
Next I
Lchamps = Left(Lchamps, Len(Lchamps) - 1)
Do While Not EOF(F)
StrSQl = "INSERT INTO [" & Nom_Table & "] (" & Lchamps & ") VALUES ("
Line Input #F, txtLine
Champs = Split(txtLine, " ")
'Si la ligne à 3 éléments : Réf Date et montant
If Ubound(Champs)>2 then
Anc_Ref = Champs(0) ' on reccupere le n° de reference
End if
strsql=strsql & "'" & anc_ref & "'" & Cdate(Replace(Champs(0),
"-", "/") & "'), " & "'" & Champs(I) & "); "
CurrentDb.Execute StrSQl
Loop
Close #F
Exit Sub
erreur:
MsgBox "Erreur sur champs N° " & I & " " & Nom_Champs(I) & " " &
Champs(I)
End Sub

@tester





Bonjour,
strsql=strsql & "'" & anc_ref & "', Cdate('" & Replace(Champs(0),
"-", "/") & "')," & Champs(I) & "); "
et aussi
Select Case LCase(Nom_Champs(I))
Case "montant":

@+