Hello,
Please find this piece of VBA macro which reads some information about all
the projects in a SQL database:
Gérard Ducouret
Sub Lecture()
Dim sQuery As String
Dim sPathFile As String, i As Integer
' Ouverture de connection à SQL Server par l'intermédiaire d'un DSN
système
Set cn = CreateObject("ADODB.Connection")
cn.Mode = adModeRead 'adModeReadWrite (Lecture seule!)
cn.ConnectionString = "DSN=" & DSN & ";UID=" & STR_USER_IDENT & " ;PWD="
& STR_PASSWORD_IDENT & ";"
cn.Open
'1ere Requête :
' Récupération des enregistrements de la table des projets de la base de
données pointé par le DSN
sQuery = "SELECT * FROM MSP_PROJECTS"
Set rst = CreateObject("ADODB.Recordset")
Set rst = cn.Execute(sQuery, , adCmdText)
sPathFile = "c:\InfoProj.txt"
Open sPathFile For Output As #1
Print #1, ""
With rst
While Not .EOF
i = i + 1
Print #1, "********************"
Print #1, "Nom du projet : " & ![PROJ_NAME]
Print #1, "Nom de l'auteur : " & ![PROJ_PROP_AUTHOR]
Print #1, "Nom de la compagnie : " & ![PROJ_PROP_COMPANY]
Print #1, "Date début du projet : " & ![PROJ_INFO_START_DATE]
Print #1, "Date d'état du projet : " & ![PROJ_INFO_STATUS_DATE]
Print #1, "Date fin du projet : " & ![PROJ_INFO_FINISH_DATE]
Print #1, "Nom du Manager : " & ![PROJ_PROP_MANAGER]
Print #1, "Heure de début par défaut projet : " &
![PROJ_OPT_DEF_START_TIME]
Print #1, "Heure de fin par défaut projet : " &
![PROJ_OPT_DEF_FINISH_TIME]
.../...
Set rst = Nothing
Print #1, "********************"
Close #1
MsgBox "Fini : " & i & " plannings dans la Base <<LocalServer>>", ,
"Gérard DUCOURET : PragmaSoft ®"
End Sub