SunRay
SunRay

Reputation: 200

Blank parent form if subform has no data

i have my regular form with a continous form attached to it. Everything works fine untill the subform has no data. Here is the subform with data
image1 enter image description here

IF there are no data in the subform, the form becomes like this.
image 2 enter image description here

I am using the following code in my on current event on my main form:

Function RefreshCOunt()
If Me.frmVerifyEquipmentSub.Form.Recordset.RecordCount = 0 Then

    Me.frmVerifyEquipmentSub.Visible = False
    Me.txtTotal = 0
    Me.Refresh

Else
    Me.frmVerifyEquipmentSub.Visible = True
    Me.frmVerifyEquipmentSub.Form.Requery
    Forms![test3].txtTotal = Me.frmVerifyEquipmentSub.Form.txtSum
    Me.Refresh
    Forms![test3].Refresh

End If
End Function

Private Sub Form_Current()
Call RefreshCOunt
End Sub

Private Sub Form_GotFocus()
Call RefreshCOunt
End Sub

Here is the code on my subform, THis function is run when my user clicks the save button.

Function RefreshCOunt()
If Me.txtCount = 0 Then
    Forms![test3].SetFocus
Else
    Me.Requery
    Forms![test3].txtTotal = Me.txtSum
    Me.Refresh
    Forms![test3].Refresh

End If
End Function

I have a text behind the subform which says "NO Available Data to be shown"

2 problems in this situation are:

  1. Empty form view as shown on image 2 (resolved as i had linked the record source of the main form to the table also used in subform)

  2. Hide the subform once the user has verified all the equipment. -currently my code only works the first time the form is loaded. -the subform does not hide once the user has verifed all the equipment

I know how to do this in report with the HAsData function but i am not sure how i can do so in Forms.

Upvotes: 1

Views: 1519

Answers (1)

Gustav
Gustav

Reputation: 55881

It sounds like your query for the main form has an inner join to the table (or a query with this table) for the subform.

Remove this join or change it to an outer join.

Upvotes: 1

Related Questions