hello all
i need an urgent help ,i started coding VBA and i need some help,i made a connection between word and oracle
and after that i bring all the columns that i need,but i have a problem,i need to put in my code a loop to say for exemple if in this column( '.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_DOMAINE""" )
i have the same field from the last to not put it ,and i dont know how to do it
this is my code :
Sub CreationDoc()
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\rita.younes\Mes documents\Mes sources de données\RQ1.odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=MSDASQL.1;Password=seolis;Persist Security Info=True;User ID=MIG_SEOLIS;Extended Properties=""DSN=MIG_SEOLIS;UID=MIG_SEOLIS;PWD=seolis;DBQ=EDFMIG;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;C" _
' , SQLStatement:="SELECT * FROM ""REQ_QUALITE_DONNEES""", SQLStatement1:= _
' "", SubType:=wdMergeSubTypeOther
With ActiveDocument.MailMerge
'Ouvre la base de données
.OpenDataSource Name:=MIG_SEOLIS, _
Connection:="DSN=MIG_SEOLIS;DATABASE:=EDFMIG;uid:=MIG_SEOLIS;pwd:=seolis", _
SQLStatement:="SELECT * FROM ""REQ_QUALITE_DONNEES"""
'Prend en compte l'ensemble des enregistrements
With .DataSource
'.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_DOMAINE"""
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
'Exécute l'opération de publipostage
Selection.Collapse Direction:=wdCollapseStart
Set myfield = ActiveDocument.Fields.Add(Range:=Selection.Range, _
Type:=wdFieldMergeField, Text:="""REQ_DOMAINE""")
MsgBox (myfield)
.Execute Pause:=False
End With
Application.ScreenUpdating = True
'Chercher la source de données
With Selection.Font
.Bold = True
.Name = "Arial"
.Size = 16
.ColorIndex = 15
.Underline = False
Call ParagraphNumbering
Selection.Style = ActiveDocument.Styles("Titre")
' Selection.Range.SetListLevel Level:=2
' ActiveDocument.Paragraphs(1).Range.ListFormat.ConvertNumbersToText wdNumberParagraph
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_DOMAINE"""
Selection.TypeParagraph
'Call ParagraphNumbering
With Selection.Font
.Bold = True
.Name = "Arial"
.Size = 16
.ColorIndex = 15
.Underline = False
Call ParagraphNumbering
' Selection.Range.SetListLevel Level:=2
Selection.Style = ActiveDocument.Styles("Titre 1")
' Selection.Range.SetListLevel Level:=2
' ActiveDocument.Paragraphs(1).Range.ListFormat.ConvertNumbersToText wdNumberParagraph
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_ID"""
Selection.TypeText Text:=":"
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_desc"""
End With
Selection.TypeParagraph
With Selection.Font
.Bold = True
.Name = "Arial"
.Size = 12
.ColorIndex = 15
Selection.Style = ActiveDocument.Styles("Titre 3")
'Selection.Style = ActiveDocument.Styles("Titre 41")
Selection.TypeText Text:="Dernière mise à jour: "
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_LAST_UPDATE"""
Selection.TypeParagraph
End With
With Selection.Font
.Bold = True
.Name = "Arial"
.Size = 12
.ColorIndex = 15
Selection.Style = ActiveDocument.Styles("Titre 3")
' Selection.Range.SetListLevel Level:=3
'Selection.Style = ActiveDocument.Styles("Titre 41")
Selection.TypeText Text:="Status : "
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_STATUS"""
Selection.TypeParagraph
End With
With Selection.Font
.Bold = True
.Name = "Arial"
.Size = 12
.ColorIndex = 15
Call ParagraphNumbering
Selection.Style = ActiveDocument.Styles("Titre 3")
' Selection.Range.SetListLevel Level:=3
'Selection.Style = ActiveDocument.Styles("Titre 41")
Selection.TypeText Text:="Gravité : "
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_GRAVITE"""
Selection.TypeParagraph
End With
With Selection.Font
.Bold = True
.Name = "Arial"
.Size = 12
.ColorIndex = 15
Call ParagraphNumbering
Selection.Style = ActiveDocument.Styles("Titre 2")
' Selection.Range.SetListLevel Level:=3
'Selection.Style = ActiveDocument.Styles("Titre 41")
Selection.TypeText Text:=" Problématique : "
Selection.TypeParagraph
End With
With Selection.Font
.Bold = False
.Name = "Arial"
.Size = 10
.ColorIndex = 1
Selection.Style = ActiveDocument.Styles("Normal")
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_PROBLEM"""
Selection.TypeParagraph
With Selection.Font
.Bold = True
.Name = "Arial"
.Size = 12
.ColorIndex = 15
Call ParagraphNumbering
Selection.Style = ActiveDocument.Styles("Titre 2")
'Selection.Range.SetListLevel Level:=3
' Selection.Style = ActiveDocument.Styles("Titre 41")
Selection.TypeText Text:="Impact : "
Selection.TypeParagraph
End With
With Selection.Font
.Bold = False
.Name = "Arial"
.Size = 10
.ColorIndex = 1
Selection.Style = ActiveDocument.Styles("Normal")
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_IMPACT"""
Selection.TypeParagraph
End With
With Selection.Font
.Bold = True
.Name = "Arial"
.Size = 12
.ColorIndex = 15
Call ParagraphNumbering
Selection.Style = ActiveDocument.Styles("Titre 2")
' Selection.Range.SetListLevel Level:=3
' Selection.Style = ActiveDocument.Styles("Titre 41")
Selection.TypeText Text:="Solution : "
Selection.TypeParagraph
End With
With Selection.Font
.Bold = False
.Name = "Arial"
.Size = 10
.ColorIndex = 1
Selection.Style = ActiveDocument.Styles("Normal")
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_SOLUTION"""
' Selection.TypeParagraph
End With
With Selection.Font
.Bold = True
.Name = "Arial"
.Size = 12
.ColorIndex = 15
Call ParagraphNumbering
Selection.Style = ActiveDocument.Styles("Titre 2")
' Selection.Range.SetListLevel Level:=3
' Selection.Style = ActiveDocument.Styles("Titre 41")
Selection.TypeText Text:="Requête :"
Selection.TypeParagraph
End With
With Selection.Font
.Bold = False
.Name = "Arial"
.Size = 10
.ColorIndex = 1
Selection.Style = ActiveDocument.Styles("Normal")
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField, Text:="""REQ_SQL"""
' Selection.TypeParagraph
'End With
End With
End With
Selection.TypeParagraph
End With
' Call sommaire
End Sub