Results 1 to 9 of 9
  1. #1
    bbxrider is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Posts
    69

    building sql string

    nothing seems to work in the where clause, see error at end of post, 3075 syntax error, missing operator



    I build the query string below and eventually execute with Set rst = dbs.OpenRecordset(strSQL1) which is where I get the error

    strSQL1 = "select transaction_history.[Activity Type] " & _
    " from transaction_history " & _
    "where [transaction_history]![Activity Type] = " & _
    """a value to match"""

    note the above resolves to:
    select transaction_history.[Activity Type] from transaction_history where [transaction_history]![Activity Type] = "someValue"

    I have tried all these where clauses:
    where [transaction_history]![Activity Type] =
    where transaction_history.[Activity Type] = (note this syntax seems to be fine in the select clause)
    where [Activity Type] =


    Click image for larger version. 

Name:	error3075-missing operator.png 
Views:	12 
Size:	4.9 KB 
ID:	19093

  2. #2
    bbxrider is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Posts
    69
    and I just tried using the same syntax that the query builder comes up with
    for the where clause and it gives the same 3075 error

    SELECT transaction_history.[Activity Type]
    FROM transaction_history
    WHERE (((transaction_history.[Activity Type])="someValue"));

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What data type is [Activity Type] field?

    Don't forget the semicolon at end of statement.

    Try:

    strSQL1 = "SELECT transaction_history.[Activity Type] FROM transaction_history " & _
    "WHERE [transaction_history]![Activity Type] = 'a value to match';"

    If you want to reference data control for parameter:

    strSQL1 = "SELECT transaction_history.[Activity Type] FROM transaction_history " & _
    "WHERE [transaction_history]![Activity Type] = '" & Me.controlname & "';"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    bbxrider is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Posts
    69
    thanks, got it working, even without the ; and with a selected value from a listbox control
    very embarrassing had a line code that messed up the string will be using it eventually as part of the logic when
    I build a where with dynamic number of 'or' criteria from list box, it should have been commented out for now
    'strSQL1 = Left$(strSQL1, Len(strSQL1) - 12)

    but now have new problem, not sure whether to continue this post or start a new
    I have to search a substring of the table field based on where there is a period in the field,
    so using a mid with instr, which I am using successfully in another access query but sql not liking it here
    new string
    strSQL1 = "select transaction_history.[Activity type], transaction_history.[detail], " & _
    " from transaction_history " & _
    "where mid(transaction_history.[Detail],InStr(transaction_history.[Detail],period)+1) = " & _
    "'campaign_list.ItemData(varItem)';"


    I used the 'period' variable to get by all the quotes within quotes to specify the search for a period - .
    dim period as string
    period = "."
    based on the error description it seems to be unhappy with the mid statement somewhere, and I presume I'm using mid here because of ms as opposed to using substring

    Click image for larger version. 

Name:	error3141-SelectStmt.png 
Views:	11 
Size:	5.1 KB 
ID:	19094

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Concatenate variables, don't include them within quotes. Even with the variable to hold dot (.), still need text delimiters. I find using apostrophe as delimiter best.
    Also extraneous comma after [detail].

    strSQL1 = "select transaction_history.[Activity type], transaction_history.[detail] from transaction_history " & _
    "where mid(transaction_history.[Detail],InStr(transaction_history.[Detail], '.')+1) = '" & campaign_list.ItemData(varItem) & "';"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    bbxrider is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Posts
    69
    thanks very much for keeping up with this, I finally gave up on the mid and am using like with wild cards, it codes so much easier and works ok for me.
    so I have ended up building this string which worked until I added the inner join, and m.[email], not sure what syntax I need here. perhaps this needs a new post? with access sql I am never quite sure when to surround a column name with the [] V=brackets

    select transaction_history.[Activity type], mid(transaction_history.[Detail],InStr(transaction_history.[Detail],'.')+1) as campaign, m.tier, transaction_history.[email] from transaction_history, [Master Email List Data Base] m INNER JOIN transaction_history ON m.Email = transaction_history.Email where transaction_history.[Detail] like '*Broker - nov campaign - Tier2>>O' OR transaction_history.[Detail] like '*Broker - Touch 2 - Tier2>>O' order by campaign, m.email;

    the error I get on the Set rst = dbs.OpenRecordset(strSQL1) is below
    Click image for larger version. 

Name:	error3074-repeatTableName.png 
Views:	8 
Size:	5.1 KB 
ID:	19096

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Never hurts to include the [] but they are necessary if names have spaces or special characters/punctuation (underscore is exception) or are reserved words.

    Try:

    strSQL1 = "SELECT transaction_history.[Activity type], Mid(transaction_history.[Detail],InStr(transaction_history.[Detail],'.')+1) as campaign, m.tier, transaction_history.[email] FROM [Master Email List Data Base] AS m INNER JOIN transaction_history ON m.Email = transaction_history.Email WHERE transaction_history.[Detail] Like '*Broker - nov campaign - Tier2>>O' OR transaction_history.[Detail] Like '*Broker - Touch 2 - Tier2>>O' ORDER BY Mid(transaction_history.[Detail],InStr(transaction_history.[Detail],'.')+1), m.email;"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    bbxrider is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Posts
    69
    thanks again for sticking with this, unfortunately still same 3074 error
    why did you suggest the mid syntax in the order by instead of the named column "campaign"?
    when I had it working without the inner join the "campaign" name seemed to work ok, at least
    I could get a value by referencing it cycling thru the rs, this worked:
    campaign = rst![campaign]


    select transaction_history.[Activity type], mid(transaction_history.[Detail],InStr(transaction_history.[Detail],'.')+1) as campaign, m.[tier], transaction_history.[email] from transaction_history, [Master Email List Data Base] as m INNER JOIN transaction_history ON m.Email = transaction_history.Email where transaction_history.[Detail] like '*Broker - nov campaign - Tier2>>O' OR transaction_history.[Detail] like '*Broker - Touch 2 - Tier2>>O' order by mid(transaction_history.[Detail],InStr(transaction_history.[Detail],'.')+1), transaction_history.[email];

  9. #9
    bbxrider is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Posts
    69
    ok, finally, phew, got it
    select transaction_history.[Activity type], mid(transaction_history.[Detail],InStr(transaction_history.[Detail],'.')+1) as campaign, m.[tier], transaction_history.[email] from [Master Email List Data Base] as m INNER JOIN transaction_history ON m.Email = transaction_history.Email where transaction_history.[Detail] like '*Broker - nov campaign - Tier2>>O' OR transaction_history.[Detail] like '*Broker - Touch 2 - Tier2>>O' order by mid(transaction_history.[Detail],InStr(transaction_history.[Detail],'.')+1), transaction_history.[email];

    evidently when using inner join the table named in the inner join also qualifies as naming in the from, so it can't be named in the from, got the idea from this post:
    http://office.microsoft.com/en-us/ac...080760180.aspx
    I also created the functionality as close as possible using the create query tool to see what it generated for sql, it came up with:
    SELECT transaction_history.[Date/Time (PST)] AS [dateTime], transaction_history.[Activity Type], transaction_history.Email, transaction_history.Detail, [Master Email List Data Base].Tier
    FROM [Master Email List Data Base] INNER JOIN transaction_history ON [Master Email List Data Base].Email = transaction_history.Email
    WHERE (((transaction_history.[Activity Type]) Like "send email" Or (transaction_history.[Activity Type]) Like "open email"))
    ORDER BY transaction_history.[Activity Type];

    so it was pretty clear from the above not to name the inner join table in the from,
    this has been quite an education and thanks, thanks again for all your support

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

Similar Threads

  1. Building a Web App?
    By Solar.Paul in forum Access
    Replies: 2
    Last Post: 12-21-2013, 09:28 PM
  2. Replies: 1
    Last Post: 08-29-2013, 06:14 AM
  3. Building a String from Numerous Subforms
    By StudentTeacher in forum Programming
    Replies: 9
    Last Post: 07-17-2011, 07:16 AM
  4. Building a FAQ
    By Karin in forum Access
    Replies: 5
    Last Post: 03-07-2011, 11:26 AM
  5. Problem with building SQL string (VBA)
    By cdpeck in forum Programming
    Replies: 1
    Last Post: 09-15-2009, 04:25 AM

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