Results 1 to 4 of 4
  1. #1
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71

    filter records to populate form on load

    I have a form called frmfilterrecordset which allows a user to input criteria for three separate fields for the next form "frmsurveyviewer" to page through one by one. On the GO button for frmfilterrecordset, the vb is:



    Private Sub CMDGO_Click()
    DoCmd.OpenForm "frmsurveyviewer", acNormal, , acFormEdit, acWindowNormal
    End Sub


    and the form that is supposed to be able to page through the corresponding records and edit them if necessary has an on load event:

    Private Sub Form_Load()
    DoCmd.ApplyFilter "filterviewer", "[Forms]![frmfilterrecordset]![TXTDATE]=[person].[day] And [Forms]![frmfilterrecordset]![COMBOLOC]=[person].[site]"
    End Sub


    I keep getting a message that this is wrong, but I don't know what to try to fix it! I've tried using [Forms]![frmsurveyviewer]![site/day] instead of [person].[site] but that didn't work either.

    Any suggestions?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Concatenate variables. Anything within quotes is a literal string.

    "[day]=#" & [Forms]![frmfilterrecordset]![TXTDATE] & "# And [site]='" & [Forms]![frmfilterrecordset]![COMBOLOC] & "'"

    Is site a text or number field? If number remove the apostrophe delimiters.
    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. #3
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71
    Quote Originally Posted by June7 View Post
    Concatenate variables. Anything within quotes is a literal string.

    "[day]=#" & [Forms]![frmfilterrecordset]![TXTDATE] & "# And [site]='" & [Forms]![frmfilterrecordset]![COMBOLOC] & "'"

    Is site a text or number field? If number remove the apostrophe delimiters.
    Thanks! This has gotten me further than I was able to get before. Site is a number, so I changed the apostrophes to #.
    DoCmd.ApplyFilter "filterviewer", "[day]=#" & [Forms]![frmfilterrecordset]![TXTDATE] & "# And [site]=#" & [Forms]![frmfilterrecordset]![COMBOLOC] & "#"
    However, when I tested it out, I got this message:

    Syntax Error in Date in query expression '[day]=#07312011*" And [site]=#9'.

    Also, does it make a difference if my [day] field is date/time type so 7/31/2011 but the txtdate is 07312011? If it does, I can change the date/time fields to numbers instead...
    Is it possible that this would be because

  4. #4
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71
    Nevermind. I figured it out enough to get by. Turns out that # designates date/time fields and not just number fields like I thought. I changed my [day] date/time field to a text field and put back the apostrophes, and left my [site] field as a number and took away the ' and the # for it. This works. Thank you!

    DoCmd.ApplyFilter "filterviewer", "[day]='" & [Forms]![frmfilterrecordset]![TXTDATE] & "' And [site]=" & [Forms]![frmfilterrecordset]![COMBOLOC] & ""

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

Similar Threads

  1. Replies: 7
    Last Post: 07-26-2011, 02:15 PM
  2. Filter specific records on sub form
    By foxtet in forum Forms
    Replies: 5
    Last Post: 06-05-2011, 12:06 PM
  3. Form - Filter on load (if data exists)
    By dilbert in forum Forms
    Replies: 0
    Last Post: 08-13-2010, 11:39 AM
  4. Replies: 0
    Last Post: 06-23-2009, 03:01 PM
  5. Filter Form records with Combo Box????
    By jgelpi in forum Forms
    Replies: 0
    Last Post: 05-19-2009, 07:05 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