Results 1 to 2 of 2
  1. #1
    tonere is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    22

    VBA to Query: Can a form control define a table in the "FROM" statement of query

    I have a module that, among other things, appends the field "SFRSTCR_PIDM" from the table "XB201370_F" to the table "XB201270_F". The module runs fine.

    When I copy the VBA from the module into a query via SQL design view, I get the error "Invalid Bracketing of name '"[Forms]![F_Create_Extracts]![OIE_Term]"'.

    I have a form "F_Create_Extracts" that has a text box "OIE_Term". The form is open and the field is populated with "201370_F". The VBA code from the module is:



    Code:
    strSQL = " INSERT INTO XB201270_F ( SFRSTCR_PIDM )" & _
    " SELECT XB_Alias.SFRSTCR_PIDM" & _
    " FROM XB" & [Forms]![F_Create_Extracts]![OIE_Term] & " AS XB_Alias;"
    DoCmd.RunSQL strSQL
    When I copy the code into query SQL design view, it looks like this:

    Code:
    INSERT INTO XB201270_F ( SFRSTCR_PIDM )
    SELECT XB_Alias.SFRSTCR_PIDM
    FROM XB" & [Forms]![F_Create_Extracts]![OIE_Term] & " AS XB_Alias;
    Is this not allowed or is my code missing something?

    Thank you all in advance for reviewing.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You can do it, but it would have to be in code as in your first example. You need it so the finished SQL resolves to the proper table name, then you can execute it in code:

    CurrentDb.Execute strSQL
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 10-16-2013, 01:39 AM
  2. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  3. Replies: 1
    Last Post: 08-23-2012, 08:32 AM
  4. Replies: 5
    Last Post: 08-03-2012, 04:20 PM
  5. Replies: 5
    Last Post: 06-25-2012, 02:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums