Results 1 to 14 of 14
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Subform not showing


    I have a form with 4 subforms. The subforms are not linked to the form nor each other. They are based on queries. If the query results are completely null, the subform will not appear on the form. I need it to appear whether or not it has any information on it. In the can shrink, I have it set to NO. The can grow is set to YES. How can I get them to show even if there is no information on them?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I did a test. My subform still shows.
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It's a known issue that forms/subforms that neither have records nor allow new records will show blank. You can test the HasData property to show something else:

    https://msdn.microsoft.com/en-us/vba...roperty-access
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Where would I enter that code to make the form visible even with no data?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I doubt you can, unless you show a fake record or let it add new records. You could make a textbox Visible that said "no records to show" or whatever.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I'm not sure why it would not be visible

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    That answers my question as to why it goes blank. Unfortunately, there doesn't seem to be an answer other than to have a message appear saying that there is no records. Thanks.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Are you reading the links? It goes blank because there are no records to display and it doesn't allow new records. Whether any of us like it or not, that's how they work, so we work around it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    What you could do is check the HasData property of the subform, and if it is false, set the AllowAdditions property of the subform to "Yes". The subform will then show a new, but blank, record.

  11. #11
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Yes. I read the links. I added the code to the Before Insert, however it still didn't show. I added the code to the On Open and that did work. I have 2 forms that won't show if there is no data. They are based on calculated queries, so there is no need to lock the fields or change the Allow Additions to NO. I have the fields unlocked and Allow Additions are YES. According to the article, that means the forms will not show with no records. I tried the workarounds and all I could get was the "No Records" window to show.

  12. #12
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Where is the HasData property of the subform? I can't find it to try it.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It's not a property you can change, so I doubt it's in the property sheet. It can be read with code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Oops! I did a little checking with Google, and found that forms don't have a HasData property - only Reports do.

    So, you can use something like this:

    Code:
      If Me![SubformControlName].Form.Recordset.RecordCount > 0 Then
        Me![SubformControlName].Form.allowAdditions = False
      Else
        Me![SubformControlName].Form.allowAdditions = True
      End If
    However:

    According to the article, that means the forms will not show with no records. I tried the workarounds and all I could get was the "No Records" window to show.
    But if the subform's record source is not updatable (e.g. a Calculated query), then setting AllowAdditions = True won't work (i.e. Access won't do it) because record additions ARE updates.

    So it appears that if there are no records to display AND the recordsource is not updatable, there is no workaround - that's just the way Access works.

    What you could do is create a textbox with a message in it something like "There are no whatever records for this job number". In design view, put the textbox on top of the subform, and set it's visible property to "No". Add something like this to the After Update event of the Job_Number control of the main form:
    Code:
      If Me![SubformControlName].Form.Recordset.RecordCount > 0 Then
           Me![SubformControlName].Visible = True
           Me![TextboxName].Visible = False
      Else
      Me![SubformControlName].Visible = False
           Me![TextboxName].Visible = True
      End If
    so the subforms don't show at all (even blank) if there is no data for them. The textboxes will tell users will know why they don't see them.
    Last edited by John_G; 01-09-2018 at 12:22 PM. Reason: Add code tags

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

Similar Threads

  1. Replies: 2
    Last Post: 01-03-2018, 04:35 PM
  2. Form with Subform showing all records
    By Cosmo Monkey in forum Forms
    Replies: 17
    Last Post: 04-28-2013, 10:03 PM
  3. Subform Not showing new records created
    By apetho17 in forum Forms
    Replies: 11
    Last Post: 04-03-2012, 12:23 PM
  4. Subform showing white
    By Rick West in forum Forms
    Replies: 2
    Last Post: 06-24-2010, 08:07 AM
  5. Subform not showing correctly
    By ricardo9211 in forum Forms
    Replies: 1
    Last Post: 08-27-2009, 07:49 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