Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    mr879 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2014
    Posts
    80
    Hey I have a question about the SQL in the Query, when I pasted the SQL code in the query that I created and ran the code it prompted me for First Nam and Last Name, Why would it do that I thought the statement only selected all the data except for Jamie and Cartman from FirstNam And LastName




    SELECT [FirstNam], [LastNam]
    FROM Table1
    WHERE ((([FirstNam])<>'Jamie') AND (([LastNam])<>'Cartman'));

  2. #17
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    It isn't finding the field names. Make sure the spellings are correct, including spaces.

    BTW, advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    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.

  3. #18
    mr879 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2014
    Posts
    80
    Cool the filtering works in the query now it was because no space was provided in the field names in the code. I just have to now incorporate it in to the Vba so the filtering is applied to the table itself, I found some information online that showed that using the DoCmd.RunSQL will work but another person replied to my post saying it is because I do not have a action query setup so it will not work.

    Here is the link to the source http://www.fontstuff.com/access/acctut15.htm



    Dim strSQL As String
    strSQL = "SELECT Table1.[First Nam], Table1.[Last Nam]" & _
    "FROM Table1 " & _
    "WHERE ((([First Nam]) <> 'Jamie') AND (([Last Nam]) <> 'Cartman'));"
    DoCmd.RunSQL strSQL
    Me.Filter = ""
    Me.Filter = "First Nam<>'Jamie' AND Last Nam<>'Cartman'"
    Me.FilterOn = True

  4. #19
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You still don't understand.

    The SQL must be the RecordSource of form. If the SQL includes the filter criteria, VBA is not needed.
    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.

  5. #20
    mr879 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2014
    Posts
    80
    Yes I know what you mean I would have to go in to design view in form and change the record source to my query file where the SQL is written, but I cannot do that alot of my my code relies on the table itself as the record source and if I changed the record source of this to the query then that means my split form will not be useful because at the bottom of the split form is the table so once the data is filtered the filtered data will be shown in the query. So I am trying to apply it on the table itself instead of the query.

  6. #21
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If the RecordSource is table, then there is no need for the SQL string in the VBA. There is no need for the RunSQL, which does not work with SELECT anyway. Just set the FilterOn property of the form.

    And because field names have spaces, must be enclosed in brackets:


    Me.Filter = "[First Nam]<>'Jamie' AND [Last Nam]<>'Cartman'"
    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.

  7. #22
    mr879 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2014
    Posts
    80
    That is the very first thing I tried but had a syntax error lol... I forgot that I needed the square brackets when there are spaces in the field name. All that work for a simple mistake now I feel stupid lol.

    This is the solution,


    Me.Filter = ""
    Me.Filter = "[First Nam]<>'Jamie' AND [Last Nam]<>'Cartman'"
    Me.FilterOn = True


    Thank You for your help!!!!!!

  8. #23
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Which is why experienced developers avoid them.
    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.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. filter subform based on option selection
    By trevor40 in forum Forms
    Replies: 2
    Last Post: 03-06-2014, 07:07 PM
  2. Filter Multiple Forms from one option box
    By chaos_05 in forum Forms
    Replies: 1
    Last Post: 12-02-2011, 10:39 AM
  3. Option button to apply filter
    By catguy in forum Programming
    Replies: 4
    Last Post: 06-23-2011, 12:10 PM
  4. Use Option Group to Filter Combo Box Values
    By dgj32784 in forum Programming
    Replies: 2
    Last Post: 06-06-2011, 12:04 PM
  5. Option Groups - change value from number to text
    By nchesebro in forum Programming
    Replies: 10
    Last Post: 02-09-2011, 03:52 PM

Tags for this Thread

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