Results 1 to 12 of 12
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    filter load


    All, using 2010; I have a data entry form. Recordsource is the table. I need the form to open ready for a new record but also only records for the current year. i.e. 2014. Right now I have this code when the form loads:
    Code:
    Private Sub Form_Load()
    Me.filter= [yearadded]=2014
    DoCmd.GoToRecord , , acNewRec
    End Sub
    Please help

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Me.FilterOn = True

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Also it likely needs to be a string:

    Me.filter= "[yearadded]=2014"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Thanks for replying. I added the code suggested and got error "invalid use of property"
    Code:
    Private Sub Form_Load()
    Me.FilterOn
    Me.Filter = "[yearadded]=2014"
    DoCmd.GoToRecord , , acNewRec
    End Sub

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I corrected "me.filteron=true" and still does work but not error.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Try using what ranman gave you, and it would go after the line setting the filter, not before.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Error: data type mismatch in expression??

    Code:
    Private Sub Form_Load()
    Me.Filter = "[yearadded]=2014"
    Me.FilterOn = True
    DoCmd.GoToRecord , , acNewRec
    End Sub

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    What is the data type of yearadded?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Text. Inherited database. Will have to fix later but for now its text

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Try

    Me.Filter = "[yearadded]='2014'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    That did it! Thanks bunches

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No problem.
    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. Filter form on load
    By hithere in forum Programming
    Replies: 1
    Last Post: 07-11-2014, 10:53 AM
  2. Getting Form to Filter Records On Load
    By Dclassen89 in forum Forms
    Replies: 12
    Last Post: 02-01-2014, 07:39 PM
  3. Filter a control on load
    By nick.h in forum Forms
    Replies: 1
    Last Post: 12-01-2011, 02:46 AM
  4. filter records to populate form on load
    By rivereridanus in forum Forms
    Replies: 3
    Last Post: 08-05-2011, 08:54 AM
  5. Form - Filter on load (if data exists)
    By dilbert in forum Forms
    Replies: 0
    Last Post: 08-13-2010, 11:39 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