How to loop & substitute ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harshakusam
    New Member
    • Apr 2009
    • 36

    How to loop & substitute ???

    Hi All,

    Code:
     
    SELECT MSysObjects.Name 
    FROM MSysObjects 
    WHERE (((MSysObjects.Type)=5));
    From above sql i will get list of queries in my MDB file

    Assume Output of above query is
    abc
    xyz
    lmn

    I have to SUBSTITUE the above values 1 by one in below AND LOOP THEM TILL LAST??

    Code:
     
    DoCmd.OutputTo acOutputQuery, "??",acFormatXLS, "D:\??" 
      
    Example 
      
    DoCmd.OutputTo acOutputQuery, "abc",acFormatXLS, "D:\abc" 
    DoCmd.OutputTo acOutputQuery, "xyz",acFormatXLS, "D:\xyz"
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    This should work nicely for you:

    Code:
    Private Sub qryLoopToXLS()
    
        Dim rs As DAO.Recordset
        Dim strSQL As String
    
        strSQL = "SELECT Name FROM MSysObjects WHERE Type=5"
    
        Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
    
        Do While Not rs.EOF
            rs.MoveFirst
            Do While Not rs.EOF
                DoCmd.OutputTo acOutputQuery, rs!Name, acFormatXLS, "D:\" & rs!Name & ".xls"
                rs.MoveNext
            Loop
        Loop
        Set rs = Nothing
    End Sub
    You may want to doublecheck that none of your queries are using any illegal filename characters, and do a replace for those character types.

    Comment

    • harshakusam
      New Member
      • Apr 2009
      • 36

      #3
      Hi Megalog,

      Thanks a lot it works.. finally my work finished with this...

      Thanks thanks....

      Comment

      Working...