Subform does not display

Y

Yam84

Hello,

I have a form and subform which i use to edit employee information.
On the main form, I have a check box; if checked, the subform will
display itself. Here is the code in the on current event of the main
form:
Private Sub Form_Current()
'On current event of main form
'Check if empLocker checkbox is selected
'then show or hide subform
If Me.empLocker = True Then
Me.frmEmpLockersLocks.Visible = True
Else
Me.frmEmpLockersLocks.Visible = False
End If

End Sub

Here is the code in the check box:
Private Sub empLocker_AfterUpdate()
'After Update of checkbox
'Check if empLocker checkbox is selected
'then show or hide subform
If Me.empLocker = True Then
Me.frmEmpLockersLocks.Visible = True
Else
Me.frmEmpLockersLocks.Visible = False
End If
End Sub

The functionality works; anytime the check box is checked, the
subform appears, but I don't always see the items on the form. The
form header is displayed, but the form detail is blank. Any idea why
this might be happening?
 
Y

Yam84

Janette:

Thank you for your response. While the resource was a good one, it did
not solve my problem. My form is not 'completely blank' just the
details section of the form. I can see the header and footer just
fine, it's just the form details that are blank.
 
J

Jeanette Cunningham

From your first post, sometimes the subform shows detail records and
sometimes it is blank.
This can happen if there are no matching records for the particular record
that is selected in the main form.

The way to check is like this:
1. Make a note of the Primary Key value on the main form for a record where
the subform is blank.
2. Create a query that shows the details records that should be in the
subform and use a where clause that finds only records that match that
Primary Key value from 1.
3. Switch that query to datasheet view and observe if there are any records.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Janette:

Thank you for your response. While the resource was a good one, it did
not solve my problem. My form is not 'completely blank' just the
details section of the form. I can see the header and footer just
fine, it's just the form details that are blank.
 
Y

Yam84

Hi Jeannette:

The issue I am having is this: My form and subform are linked via
empID. The relationship is not a one to many, but one to one. In the
first form , i click a check box if I want to assign a locker to an
employee and then the subform becomes visible. I should then be able
to add to the subform, however the details section is not available.
I read somewhere the this happens when 2 conditions are true, and
tried the work around, however when I use the work around, I can see
the details section of the subform, but I can not add records to it.
The work around was in the before insert event:
Private Sub Form_BeforeInsert(Cancel As Integer)
Cancel = True
End Sub

So there is no record in the subform matching the record in the first
form, until I add it. The problem is AFTER it has been added (if it
even allows me to add it) I am unable to view the results in the
details section.
 
Y

Yam84

Hi Janette,

I thought I responded, but I haven't seen the response so here is my
2nd attempt at responding:
My form and subform are connected via empID. there is a one to one
relationship between employee and locker and employee and lock. Each
employee can have one and only one lock and locker. the way i have it
set up is that the user checks a box to indicate whether or not the
employee is issued a locker; if they get a locker, after pressing the
check box, the subform will be displayed. This works. What does not
work is adding the record at all in the subform. From the source you
gave me, I learned that my details section could not be showing up for
one of two reasons and the way around the problem was in the before
insert event of the subform, to add this:

Private Sub Form_BeforeInsert(Cancel As Integer)
Cancel = True
End Sub

Although now I can see the details sections, I am unable to make
updates to the subform.
"From your first post, sometimes the subform shows detail records and
sometimes it is blank. This can happen if there are no matching
records for the particular record that is selected in the main form."
--I do not expect to see records for all employees because all emps
will not be provided lockers. the emps who will be assigned lockers
but have not, do not have a record in the query I have which tells me
who has been assigned lockers at this point. My form and subform are
linked correctly and the empIDs always match.
 
J

Jeanette Cunningham

I avoid working with form and subform in 1:1 relationships, so I am not much
help to you.
A suggestion is to use a separate form instead of a subform.
Open the form to display the locker using a where condition and in acDialog
mode.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Hi Janette,

I thought I responded, but I haven't seen the response so here is my
2nd attempt at responding:
My form and subform are connected via empID. there is a one to one
relationship between employee and locker and employee and lock. Each
employee can have one and only one lock and locker. the way i have it
set up is that the user checks a box to indicate whether or not the
employee is issued a locker; if they get a locker, after pressing the
check box, the subform will be displayed. This works. What does not
work is adding the record at all in the subform. From the source you
gave me, I learned that my details section could not be showing up for
one of two reasons and the way around the problem was in the before
insert event of the subform, to add this:

Private Sub Form_BeforeInsert(Cancel As Integer)
Cancel = True
End Sub

Although now I can see the details sections, I am unable to make
updates to the subform.
"From your first post, sometimes the subform shows detail records and
sometimes it is blank. This can happen if there are no matching
records for the particular record that is selected in the main form."
--I do not expect to see records for all employees because all emps
will not be provided lockers. the emps who will be assigned lockers
but have not, do not have a record in the query I have which tells me
who has been assigned lockers at this point. My form and subform are
linked correctly and the empIDs always match.
 

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