Consulting

Results 1 to 3 of 3

Thread: FROM syntax not recognizing table

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Mar 2012
    Posts
    1
    Location

    FROM syntax not recognizing table

    Good day all, I am hoping someone can shine the light on my mistakes.
    I have an ADO code the runs in excel pulling info from an MS access DB.
    The issue is when I pull FROM a table that has one word it works fine but if the table has more than one word with a space etc it does not work.
    If i replace the "Profiles 3-4" below with one word like "Helmet" it works but i have so many tables in my DB renaming all to a single word is not realistic. Any help would be apprecited.
    BTW im not new to excel VBA but access i am ver much a novice.
    Thx,
    RKeev
    This is the selection of code where it errors:
    [VBA]
    Set Recordset = New ADODB.Recordset
    With Recordset
    ' Filter
    Src = "SELECT * FROM Profiles 3-4 WHERE BDE = 'HBCT' "
    [/VBA]

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    447
    Location
    If possible, rename the table to a single word with no spaces, punctuation marks, etc. ... begin the name with a letter, and use only letters, digits, and the underscore character for the rest of the name.

    If you must keep that name, surround it with square brackets to avoid confusing the database engine.


    [VBA]Src = "SELECT * FROM [Profiles 3-4] WHERE BDE = 'HBCT' "[/VBA]

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    hansup makes an excellent point. It's a good idea when setting up your database to not include spaces in the name of anything - tables, fields, queries, forms ...

    I'd suggest you do some reading on the Leszynski/Reddick naming conventions - it's a good habit to get into, and makes your database much easier to maintain.

    We are what we repeatedly do. Excellence, therefore, is not an act but a habit.
    Aristotle

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •