Results 1 to 4 of 4
  1. #1
    Deutz is offline Advanced Beginner
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    51

    Concat in SQL creates unwanted spaces

    Using Access 2003

    I have some VBA code that creates an SQL string which concats three fields in a table with a string contained in a recordset and it outputs to another table ok except that there are a number of spaces between the Channel field and the rs!fldMetricType field. I've tried using the TRIM function as per code below but no improvement. Any help would be appreciated.



    SELECT Stream & Channel & '" & Trim(rs!fldMetricType) & "' & MarketSegment as fldKey ....... etc etc


    Thanks in advance

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    the one thing I notice about that is the use of single quote marks. you don't need them, and it shouldn't work the way it's written anyway. It should be:
    Code:
    "SELECT Stream & Channel" & Trim(rs!fldMetricType) & "MarketSegment as fldKey ....... etc etc"
    and are you sure the spaces aren't coming from the other field? CHANNEL? to be sure, trim that one as well.

    btw, concating with single quote marks is only ever needed in criteria clauses, with string values only.

  3. #3
    Deutz is offline Advanced Beginner
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    51
    Thanks Adam

    You are right; the spaces were coming from the Channel field and the SQL worked fine once I trimmed it.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    great!


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

Similar Threads

  1. protecting records from unwanted edits
    By Hunt2871 in forum Security
    Replies: 2
    Last Post: 08-01-2010, 10:49 PM
  2. subform creates duplicate record
    By jheintz57 in forum Forms
    Replies: 0
    Last Post: 03-29-2010, 11:50 AM
  3. Unwanted Dialog Box
    By ntallman in forum Programming
    Replies: 3
    Last Post: 03-26-2010, 11:11 AM
  4. concat problem
    By leahcim_32 in forum Access
    Replies: 1
    Last Post: 08-28-2009, 05:31 AM
  5. Subform creating new unwanted entries
    By Rpatrick in forum Access
    Replies: 1
    Last Post: 08-14-2009, 03:08 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