Disappearing subform

T

Tony

My main form displays information for one vehicle. The subform displays
issues associated with that vehicle. The subform is linked to the main form
by Project_ID and Vehicle_Num. This is an informational form so I set Allow
Additions to No. What happens is when I select a vehicle that has no issues
the issue subform disappears until I select a vehicle that has issues. This
does not happen if I set Allow additions to yes. I have an autonumber field
in the subform that displays "(AutoNumber)" for a new record, otherwise Allow
additions would be acceptable. Is there any way I can display a blank issue
subform on the screen? Thanks.

Tony
 
D

Dirk Goldgar

Tony said:
My main form displays information for one vehicle. The subform
displays issues associated with that vehicle. The subform is linked
to the main form by Project_ID and Vehicle_Num. This is an
informational form so I set Allow Additions to No. What happens is
when I select a vehicle that has no issues the issue subform
disappears until I select a vehicle that has issues. This does not
happen if I set Allow additions to yes. I have an autonumber field in
the subform that displays "(AutoNumber)" for a new record, otherwise
Allow additions would be acceptable. Is there any way I can display a
blank issue subform on the screen? Thanks.

A bound form that has no records to display, and on which no records may
be added, will always be displayed as blank. Do you really want to
display a form with empty controls, suggesting to the user that data
entry may be made, when it can't? If so, you could probably leave the
form's AllowAdditions property set to Yes, but set all the bound
controls' Locked properties to True, use the form's BeforeInsert event
to cancel any update, and maybe hide the autonumber field.

Or you could have a label that says "No Records on File", positioned on
top of the subform control, and make it visible only when there are no
records.
 
T

Tony

Thanks. "No records on file" would work. How do I know programatically after
selecting a different vehicle if the record set in the subform is empty?
 
D

Dirk Goldgar

Tony said:
Thanks. "No records on file" would work. How do I know
programatically after selecting a different vehicle if the record set
in the subform is empty?

I think you could use the Current event of the form to check the
RecordCount property of the Recordset of Form object of the subform
control, along these lines:

'----- start of example code -----
Private Sub Form_Current()

With Me!sfmYourSubformControl
If .Form.Recordset.RecordCount = 0 Then
.Visible = False
Me!lblNoRecords.Visible = True
Else
.Visible = True
Me!lblNoRecords.Visible = False
End If
End With

End Sub
'----- end of example code -----

I haven't tested that, and it's possible that there might be a timing
issue that would make the recordset be not yet updated. Try that,
though, and if it doesn't work, you can use a DLookup or DCount
expression to find out how many records the subform ought to be
displaying. Please post back with your results.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top