Results 1 to 6 of 6
  1. #1
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239

    Can't reference to subform when record count is 0

    Hi,




    I want to perform some action when Userform has 0 record count on Main Form load event. It's not working, whatever reference I use for subform

    Here It is (here I tried only to set Dataentry to true, so that fields of subform would appear If there are no records - otherwise It returns me only labels of fields...continous subform, tabular design):

    Code:
    Private Sub Form_Load()
    
    
    If Me.MySubform.Form.Recordset.RecordCount = 0 Then
    
    Me.MySubform.Form.DataEntry = True
    
    
    End If
    
    
    End Sub

    However, this Main form is opened from another form via cmdbutton (simple Docmd.OpenForm, but with desired .Recordsource), maybe that is problem in reference ?

  2. #2
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    I have this statement in my form wich show the subform when the recordcount is greater then zero.
    I have only editted the form names etc for my own discretion.

    Maybe you can edit the code to your situation.

    Code:
    If Me.MyCheckMark = True Then
        With Me![MySubForm].Form
            .Visible = (.RecordsetClone.RecordCount > 0)
        End With
    Else
    Me![MySubForm].Form.Visible = False
    End If
    I know you have no checkmark but again, maybe you can edit a little to make it work.

  3. #3
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    thanks for response,

    but It's not working. I tried this :

    Code:
    Private Sub Form_Load()
    
    
      With Me![MySubform].Form
        If (.RecordsetClone.RecordCount > 0) Then
        Me![MySubform].Form.Visible = False
        End If
     End With
    
    
    End Sub

    MySubform is not visible, whether has records or not. Any idea on how to change this code ?

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    how about providing a sample database with some junk data in it.

  5. #5
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    Sure,

    here It is. Form1 is "search" form - based on criteria Form2 opens, with subform. Check VBA for that, and Subfom_Load event. On Form2 I also added explanation of what exactly I'm trying to achieve.
    Attached Files Attached Files

  6. #6
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    Solved. Code from post#1 is ok, I just need to put It in separate module and call It right after SQL for subform recordsource executes. This way I can set Textbox to visible, and If there are no records in Subform I can display "No records" in Textbox.

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

Similar Threads

  1. If subform record count 0 Then..
    By Lukael in forum Programming
    Replies: 1
    Last Post: 02-22-2016, 01:42 PM
  2. reference objects on subform
    By gammaman in forum Modules
    Replies: 2
    Last Post: 08-27-2015, 07:31 AM
  3. Subform record count warning message
    By FJM in forum Access
    Replies: 5
    Last Post: 01-29-2013, 08:17 AM
  4. Replies: 5
    Last Post: 08-09-2012, 12:49 PM
  5. Can't reference control in subform
    By evanscamman in forum Forms
    Replies: 0
    Last Post: 12-25-2007, 06:47 PM

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