Format problem with SELECT FROM IN

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mabrynda
    New Member
    • Jan 2010
    • 24

    Format problem with SELECT FROM IN

    I'm copying a table into a newly renamed database with the statement SELECT INTO IN FROM. As long as I provide the full path within the single quotation mark everything works fine. But I want to provide the new database name as a a string. I tried all the combinations (single quotation marks, double qutation marks) but nothing works, it always gives me an error. Anybody has solution for that? Any help will be more than appreciated. Here is the code I'm trying to execute.
    Code:
     
    strDBName = "C:\MATLAB\DB\NEWPROJECTS\NEW_DBPROJECT"
    
    '******This is the working statement
    'DoCmd.RunSQL " SELECT * INTO [tblPortfolioRepartition] IN 'C:\MATLAB\DB\NEWPROJECTS\NEW_DBPROJECT' FROM [tblPortfolioRepartition] "
    
    '******This is the non-working statement
    DoCmd.RunSQL " SELECT * INTO [tblPortfolioRepartition] IN ' ' & strDBName & ' ' FROM [tblPortfolioRepartition] "
  • mabrynda
    New Member
    • Jan 2010
    • 24

    #2
    Sorry for bodering you.
    I did something wrong. The statment works with:
    Code:
    DoCmd.RunSQL "SELECT * INTO [tblPortfolioRepartition] " & _
                 "IN '" & strDBName & "' " & _
                 "FROM [tblPortfolioRepartition] "
    Last edited by NeoPa; Mar 15 '10, 02:29 PM. Reason: Please use the [CODE] tags provided.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Try:
      Code:
      DoCmd.RunSQL "SELECT * INTO [tblPortfolioRepartition] IN '" & strDBName & "' FROM [tblPortfolioRepartition]"

      Comment

      • mabrynda
        New Member
        • Jan 2010
        • 24

        #4
        Thanks,
        It works fine.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          You are quite welcome.

          Comment

          Working...