Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-05
3
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
hnasr earned 2000 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 31

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

688 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