Solved

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

Posted on 2008-10-05
3
229 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

758 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

25 Experts available now in Live!

Get 1:1 Help Now