Results 1 to 2 of 2
  1. #1
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169

    where statement not right

    On my form I have the following and my where statement does not seem to work. Tried altering () and [] but still nothing.

    Private Sub FLJan11_Click()

    dim strsql as string
    dim db as dao.database
    dim rs as dao.recordset

    set db = currentdb(focus)

    strsql = "select focuslist2011.pol, focuslist2011.customer, focuslist2011.subcntjan11
    from focuslist2011
    where [focuslist2011.pol]=[forms]![focuslist]![pol]"

    set rs = db.openrecordset(strsql, dbopendynaset)



    more code for loop and excel below the above code. It is erroring by displaying red on my SQL section.

  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,641
    I assume you have it on different lines like that? First, put it all on one until you get it right. Second you need to concatenate the form reference:

    "...where [focuslist2011.pol]=" & [forms]![focuslist]![pol]

    or if pol is a text field:

    "...where [focuslist2011.pol]='" & [forms]![focuslist]![pol] & "'"
    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: 7
    Last Post: 08-17-2011, 01:49 PM
  2. If Statement
    By MFS in forum Programming
    Replies: 13
    Last Post: 06-16-2011, 08:54 PM
  3. if statement
    By sirlosi in forum Queries
    Replies: 4
    Last Post: 03-07-2011, 11:26 AM
  4. If Then Statement Help
    By Kapelluschsa in forum Programming
    Replies: 5
    Last Post: 08-11-2010, 09:24 AM
  5. IIf Statement
    By dref in forum Forms
    Replies: 2
    Last Post: 07-16-2010, 02:46 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