Results 1 to 8 of 8
  1. #1
    annmv888 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2016
    Posts
    15

    Red face Filter a query on one form with data from another form

    I need help with passing data from one form's query to another.

    I have a form with mainform and a subform. The mainform has the lngTrainerID field. The subform has the dtmDate field. I use that field to create two fields in my query, FirstDayofWeek: ([dtmDate]-Weekday([dtmDate]))+2 and LastDayofWeek: ([dtmDate]-Weekday([dtmDate]))+6. These appear on my subform along with the dtmDate field.

    I want to link this form to another form by using the lngTrainerID, FirstDayofWeek and LastDayofWeek fields. The lngTrainerID field iinks fine using DoCmd.OpenForm "frmWeeklyHours", acNormal, , "lngTrainerID = " & Me.lngTrainerID but I want to also link the FirstDayofWeek and LastDayofWeek fields the same way but it won’t work. These two fields are also in my second forms query. I have tried everything in know but can’t get it to work. Can anyone help me? Thanks in advance.


  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,652
    The second form could be based on a query that included a date criteria, or you should be able to add to your wherecondition:

    "lngTrainerID = " & Me.lngTrainerID & " AND DateField Between #" & Me.FirstDate & "# And #" & Me.SecondDate & "#"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    annmv888 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2016
    Posts
    15
    Thanks for the help. I pasted your code but now I get an error, "Member or data member not found" for the Me.lngTrainerID. This works without the date part.

    I also tried taking the Me.lngTrainerID part out to see if the dates would work on their own and I get the same message on the Me.FirstDate.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Did you change all the names to match your field and textbox names?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    annmv888 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2016
    Posts
    15
    Yes I did and if I take out the line from & " AND... it works again for the lngTrainerID.

    Also, as soon as I type the me. the list appears and I can find the field lngTrainerID. When I did that for my me.FirstDayofWeek field I can't find that field in the list.

  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,652
    If those are on the subform (more accurately, not in the object containing the code), you'd need the full reference to them:

    Forms Refer to Form and Subform properties and controls
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    annmv888 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2016
    Posts
    15
    Thanks so much that worked great!

  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,652
    Happy to help and welcome to the site by the way!
    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. Opening a form to filter Data (VBA)
    By CT_AccessHelp in forum Forms
    Replies: 11
    Last Post: 03-10-2016, 01:51 PM
  2. Replies: 5
    Last Post: 12-09-2015, 11:28 AM
  3. Replies: 2
    Last Post: 11-25-2013, 10:56 AM
  4. Replies: 6
    Last Post: 09-23-2013, 03:17 PM
  5. Referencing split form data / filter
    By stephenaa5 in forum Programming
    Replies: 2
    Last Post: 09-14-2010, 08:48 AM

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