show msg box when form returns no record

siamandm
BronzeLounger
Posts: 1227
Joined: 01 May 2016, 09:58

show msg box when form returns no record

Post by siamandm »

Hi

i would like to show a msg , when a sub form is empty and not return no data ?

regards

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: show msg box when form returns no record

Post by HansV »

You could create a label somewhere on the subform with caption "No Records". Set its Back Style property to Normal and its Visible property to No.

In the On Current event of the subform:

Code: Select all

Private Sub Form_Current()
    Me.lblNoRecords.Visible = (Me.RecordsetClone.RecordCount = 0)
End Sub
where lblNoRecords is the name of the label
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1227
Joined: 01 May 2016, 09:58

Re: show msg box when form returns no record

Post by siamandm »

thank you Hand
i have another question please, i tried to make this label on top of sub form but i couldn't i tried many ways any idea how to make a a label on top of sub form?

regards

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: show msg box when form returns no record

Post by HansV »

My suggestion was to create the label in the subform itself, for example on its Detail section. If you want the label to be on the main form, the code would have to be different.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1227
Joined: 01 May 2016, 09:58

Re: show msg box when form returns no record

Post by siamandm »

when i put the lable inside the subform it can cover all the controls except one of the ... I tried all the way but this control comes up on top of the label, that's why i changed the way the first combo box will come over the label always ... any suggestion?

siamandm
BronzeLounger
Posts: 1227
Joined: 01 May 2016, 09:58

Re: show msg box when form returns no record

Post by siamandm »

i found a trick if its ok , i created a tiny text box and make the set focus on form load to that text box ... now the label is cover everything.