Attribute VB_Name = "Module1"
Public Sub Main()
   Dim strPath          As String

   ' Normalize Path
   strPath = App.Path
   If Right$(strPath, 1) <> "/" Then
      strPath = strPath & "/"
   End If

   CreateAuthorsXML strPath & "Authors.xml"
End Sub

Function FileExists(ByVal strFileName As String) As Boolean

  FileExists = CBool(Len(Dir$(strFileName, vbNormal _
                                         + vbHidden _
                                         + vbSystem _
                                         + vbVolume _
                                         + vbDirectory)))

End Function

Sub CreateAuthorsXML(strXMLFile As String)
  Dim rsAuthors      As ADODB.Recordset

  Set rsAuthors = New ADODB.Recordset

   ' Open recordset with a few columns
   ' Limit to just a few records with WHERE clause
   rsAuthors.Source = "SELECT au_id, au_fname, au_lname " _
                    & "FROM Authors" ' WHERE au_id < 5"

   ' Change localhost below to your SQL Server name if necessary
   rsAuthors.ActiveConnection = "Provider=sqloledb;Data Source=localhost;" _
                              & "Initial Catalog=pubs;User Id=sa;Password="

   ' All set to open the recordset...
   rsAuthors.Open

   If FileExists(strXMLFile) Then Kill strXMLFile

   rsAuthors.Save strXMLFile, adPersistXML

   rsAuthors.Close
   Set rsAuthors = Nothing

End Sub


