How to check if a subform is empty?

adamtate94

Registered User.
Local time
Today, 12:05
Joined
Sep 6, 2016
Messages
31
Hi guys,
been playing around with VBA on how to check if a subform has records displaying in it or now,
i've tried things like if Me!subfrmHazardRAMS.Form!RecordSource = "" Then.


Just getting error..

Thanks in advance
 
try

Me.subfrmHazardRAMS.Form.count

use dots(.) rather than bangs (!)
 
Last edited:
Thanks for the reply, getting this error..
Image Attached
 

Attachments

  • errormsg.png
    errormsg.png
    42.3 KB · Views: 480
You can load a copy of the subform's recordset into memory then check if it's empty.
Code:
Dim rs as RecordSet

Set rs = me.subfrmHazardRAMS.Form.RecordsetClone
If rs.BOF and rs.EOF Then
    MsgBox "No Records"
End If
 
which line is causing the error? click on debug to see which one is highlighted

for the code to work, subfrmHazardRAMS has to be a subform on the form from where it is run

as you type me. you will be prompted for all the available objects, subfrmHazardRAMS should be one of them, as is (presumably) combo183
 
The Recordset code has also given me an error on this line :


(Attached)
 

Attachments

  • recrdseterror.png
    recrdseterror.png
    21.6 KB · Views: 360
please don't just read the first line of the post. read it all and respond to each part. I don't have time to keep reminding you.

Answer these

for the code to work, subfrmHazardRAMS has to be a subform on the form from where it is run
is it?

as you type me. you will be prompted for all the available objects, subfrmHazardRAMS should be one of them, as is (presumably) combo183
does it (and combo183) appear?
 
The subreport is part of the form i am adding the code to, still getting an error. Please see attached
 

Attachments

  • subfrmerror.png
    subfrmerror.png
    41 KB · Views: 191
The expression you entered refers to an object that is closed or doesn't exist. On the line with the Me.subfrmHazardRAMS.Form.count on.

Thanks
 
it works for me. Alternative try

Me.subfrmHazardRAMS.Form.recordset.recordcount
 
one other thought - I presume your subform does have a sourceobject
 

Users who are viewing this thread

Back
Top Bottom