Provided by Allen Browne. Created: August 2006. Last updated: January 2010.
The entire Detail section of a Microsoft Access form goes blank sometimes. The text boxes you see in design view disappear when you go to use the form, leaving nothing but empty space.
It happens when both these conditions are met:
Condition (a) can be triggered in several ways. Examples:
Condition (b) can be also be triggered by several things:
You can demonstrate the problem with any form, just by setting its Data Entry property to Yes, and Allow Additions to No.
If it has Form Header and Form Footer sections, controls in these sections will still be visible but they may not work properly. (This is one of the issues discussed in Incorrect display of data.)
You cannot prevent this from happening, unless you can avoid (a) and (b) being true at the same time.
If you have set Allow Additions to No so as to prevent new records, there is a simple workaround. Set Allow Additions back to Yes, so the form can show the new record when there are no others. You can prevent new records by canceling the BeforeInsert event of the form. Steps:
If you cannot prevent condition (b), you might be able to prevent condition (a). For example, if you are opening a form with a WhereCondition that could result in no records, you might prefer to display a dialog rather than the blank form. To do that, cancel the Open event of the form:
Private Sub Form_Open(Cancel As Integer) If Me.RecordsetClone.RecordCount = 0 Then Cancel = True MsgBox "No records" End If End Sub
(Note: The procedure where you used OpenForm will be notified with error 2501 that the form did not open. Use error handling in that procedure to trap the message.)
There are times when you cannot prevent (a) and (b) happening together. A complex search form may have to use a read-only query, and the user's criteria may return no results. For these cases, place the criteria boxes in the form header section, and accept the fact that users will be okay if they see nothing when the search returns no results.
January 2010 update: In Access 2007 and later, check that the form's Filter On Load property is set to No so that it does not automatically apply a previously saved filter when you open the form.
|Home||Index of tips||Top|