Solved

Access: how do you test for a blank sub form?

Posted on 2008-10-05
3
231 Views
Last Modified: 2013-11-28
Hello,

I would like to test an Access sub form using VBA to see if it's empty. If it is, I would like to modify controls on the main form.

The sub form does not allow edits, additions, or deletions. How do I test the sub form to find out when it's empty? Also, do I use the test in the main form onCurrent event?

Thanks
0
Comment
Question by:BradleyOnTheRoad
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
hnasr earned 500 total points
ID: 22645781
Create a record set for the table or query of the subform where the link field = main form link field.
If rs.RecordCount=0 then
  'it is empty
End if

Ex:
Private Sub Command23_Click()
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("Select * from tblY where M= " & Me!M)
    If rs.RecordCount = 0 Then
        MsgBox ("Subform is empty")
   End If
End Sub
       
    rs.Close
0
 
LVL 30

Expert Comment

by:hnasr
ID: 22645788
SubForm tblY,  record source = tblY
Link fields=M
0
 

Author Closing Comment

by:BradleyOnTheRoad
ID: 31503232
Thanks
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now