Results 1 to 3 of 3
  1. #1
    NickvdM is offline Novice
    Windows 10 Office 365
    Join Date
    May 2022
    Posts
    3

    Subform does not respond to requery

    Greeting to all,

    I have a situation where I have a parent form, containing a subform. These are basically based on the same table, although I am using a query as the datasource for the subform because it must only display records (from the same table as the parent form,) relevant to the current record in the parent form, if any such records exist. I have tried a couple of things and read some forums and FAQs, but none seem to solve my problem. I've been struggling with this for days now! :'-(

    Below is the VBA code I've tried which I though would work. (Some statements are comments. The others are VBA statements which I personally have the idea SHOULD work but doesn't otherwise I wouldn't be posting this.)

    If Me.ysnHasComponents Then
    ' Forms![sfrmPathologyTest].SetFocus (Runs the GotFocus even in subform, but doesn't work
    ' sfrmPathologyTest.Requery
    ' sfrmPathologyTests.Form.Refresh
    ' Me.sfrmPathologyTests.Form.RecordSource = "SELECT * FROM tblPathology WHERE txtIsComponentOf" & _
    ' "=" & [Forms]![frmPathologyTests]![cboIsComponentOf] & ";" ' This SQL statement format and syntax may be wrong; I've given up on it.


    ' THESE FOLLOWING TWO STATEMENTS ARE WHAT I BELIEVE SHOULD WORK, BUT IT DOESN'T
    sfrmPathologyTests.Form.Requery
    sfrmPathologyTests.Visible = True
    Else
    sfrmPathologyTests.Visible = False
    End If

    I realise similar questions may have been asked before but the proposed solutions aren't solving my problem.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Just set master & child link fields
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    I agree that is the easiest as no code is required but if you want to also hide the subform you need to add code to the Current event of the main form (no need to include the check to the boolean field ysnHasComponents, just check if the subform's recordset has any records):

    Code:
    Me.sfrmPathologyTests.Form.RecordSource = "SELECT * FROM tblPathology WHERE txtIsComponentOf = " & Me.cboIsComponentOf  'choose this line if txtIsComponent is numeric 
    
    
    Me.sfrmPathologyTests.Form.RecordSource = "SELECT * FROM tblPathology WHERE txtIsComponentOf = '" & Me.cboIsComponentOf & "'"  'choose this line if txtIsComponent is text
    
    
    Me.sfrmPathologyTests.Visible=Me.sfrmPathologyTests.Form.Recordset.RecordCount>0
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 2
    Last Post: 10-09-2021, 07:15 AM
  2. requery 1 subform after activity on another subform
    By markjkubicki in forum Programming
    Replies: 5
    Last Post: 10-24-2019, 03:29 PM
  3. Subform won't requery
    By Heathey94 in forum Access
    Replies: 36
    Last Post: 09-23-2016, 10:09 AM
  4. requery subform
    By nswhit in forum Forms
    Replies: 2
    Last Post: 05-16-2013, 09:34 AM
  5. Replies: 3
    Last Post: 04-17-2012, 10:28 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